1

I am using the R package data.table to deal with big data files. However, I found it cannot be used with opencpu.

For example, my R function is,

foo <- function() {
    library(data.table)
    iris = data.table(iris)
    o = iris[,.N,Species]
    return(list(o,dim(o)))
    }

and I tried to ocpu.call this function by running,

  var req = ocpu.call("hello",{},
   function(session){
     console.log(session)
   });

And when I check the session, the result output is

[[1]]
Null data.table (0 rows and 0 cols)

[[2]]
[1] 0 0

So you can see that opencpu cannot be used with R package, data.table.

I wonder if this is right or I just missed something here?

Frank
  • 66,179
  • 8
  • 96
  • 180
  • I even checked http://jsfiddle.net/opencpu/7torLdk9/. It works fine there but not locally. I cannot figure out the reason.. – user7117436 Nov 15 '16 at 16:48

1 Answers1

0

opencpu works by providing ajax/client access to R packages in a server's R library location, so in your custom package's NAMESPACE file, make sure these lines are there

export(my_custom_function_name)
import(data.table)

The export() line should already be in there. You should also use the explicit "data.table::data.table(example_df)" namespace syntax convention in your R functions.

I am curious myself why the import() is required (by opencpu?), but I'm new to R package development. I notice this public example from the opencpu public app page uses import(ggplot2). For namespaces, this has been helpful.