0

OpenCPU developers, I am trying to use OpenCPU to run custom functions code and want to return more than one parameter using "list". Something like that:

result = list(x=data.frame(a),y=data.frame(b)) 
return (result)

It works well, but OpenCPU packing result like one variable (R/.var) and I can download it only like JSON in separate view. Serialisation in this case is very inefficient:

{
    "x": [
    { "PC1": -0.0134, "PC2": -0.8164 }
    ,
    { "PC1": -0.2206, "PC2": -0.6093 }
    ,
    { "PC1": -1.0569, "PC2": -0.3061 }
    ],

    "y": [
    { "hp": 270, "qsec": 20.36 }
    ,
    { "hp": 270, "qsec": 20.92 }
    ,
    { "hp": 201, "qsec": 22.46 }
    ]
}

If download like CSV OpenCPU performs replication of scalars and cannot join data frames with different rows number.

Is there any way to download $x and $y separately? Any more optimal serialisation suggestions?

1 Answers1

0

As the R opencpu server executes the incoming request concurrently, you could split the function into two functions, and fire these functions simultaneously, the one giving $x and the other $y.

Good question btw about speed and serialization....