none
R Functions in Execute R Script RRS feed

  • Question

  • Hello, much appreciated if the learned ones can help me here.

    I followed the excellent quick start by Blackmist.

    My R script uses the function graph.data.frame from igraph to turn the data frame into a graph object and it throws an error 0063  Error: Mapped variable must be of class type data.frame at this time.

    Does this mean the my data frame in ML is not the same type of data frame as in R? 

    In R
    sample1<-read.csv("File Location")
    graph1<-graph.data.frame(sample1)

    In ML
    sample1<-maml.mapInputPort(1)
    graph1<-graph.data.frame(sample1)


    Monday, February 23, 2015 9:32 AM

Answers

  • Hi,

    The problem is that you can only return objects where "is.data.frame" is true and graph data frames from the igraph library do not have this property.

    Here are a couple of work arounds:

    2. To return arbitrary R objects as data.frames, you can serialize
    them into a byte array using:

    as.data.frame(as.integer(serialize(g,con=NULL))); <o:p></o:p>

    3. Alternatively, igraph provides a function, get.data.frame to
    get the edge and vertex information as data frames. So you can do something
    like this:<o:p></o:p>

    vertices <- get.data.frame(g, what="vertices")

    or
    edges <- get.data.frame(g, what="edges")

    Each of these are a data.frame you can return them individually from the Execute R Script module.

    Does this help?

    Margaret

    Monday, February 23, 2015 9:13 PM
    Moderator