For dataframe
objects you can use HTTP GET
and set the dataframe
argument:
GET http://localhost:7177/ocpu/tmp/x000a0fb8/json?dataframe=rows
For example the Boston
object from the MASS
package is a dataframe as well:
https://cran.ocpu.io/MASS/data/Boston/json?dataframe=columns
https://cran.ocpu.io/MASS/data/Boston/json?dataframe=rows
For HTTP GET
requests to a .../json
endpoint, all the http parameters are mapped to arguments in the toJSON
function from the jsonlite package. You can can also specify other toJSON
arguments:
https://cran.ocpu.io/MASS/data/Boston/json?dataframe=columns&digits=4
To see which arguments are available, have a look at the jsonlite manual or this post.
Note that this only works if you do the 2 step procedure: first a HTTP POST
on a function that returns a dataframe
, followed by retrieving that object in json
format with a HTTP GET
request. You can not specify toJSON
parameters when you do the 1-step shortcut where you fix the POST
request with /json
, because in POST
requests the HTTP parameters always get mapped to the function call.
The reason for this default is that the row based design seems to be the most conventional and interoperable way of encoding tabular data. The jsonlite paper/vignette goes into some more detail. Note that it also works the other way around: you don't have to call the data.frame
function to create a dataframe, just posting an argument in the form:
[{"xx":1,"yy":6},{"xx":2,"yy":7},{"xx":3,"yy":8}]
will automatically turn it into a data frame:
curl https://public.opencpu.org/ocpu/library/base/R/summary/console -d object='[{"xx":1,"yy":6},{"xx":2,"yy":7},{"xx":3,"yy":8}]'