none
In REST API can we return binary file or data.frame (or jsonlite::toJSON(data.frame))? RRS feed

  • Question

  • I would like to transfer some data.frame like data. is it possible to transfer data.frame? binary would be ideal (write as RDS) but jsonlite::toJSON() is also ok. i guess jsonlite is more do-able. Does anyone have suggestions?

    thank you.

    Best,

    Ricky

    Thursday, March 9, 2017 1:34 AM

All replies

  • an update: i am able to return a data.frame, but if i do this:

    r1 <- POST("http://someendpoint:port/api/somename/",add_headers(Authorization=paste0("Bearer ",auth)),
               body=list(n=3)
               , encode='json',config = httr::config("proxy"=''))
    
    r2 <- jsonlite::fromJSON( content(r1, as = 'text') )$outputParameters$answer
    
    class(r2)
    # is a list instead of data.frame!
    
    # so i need to do an additional step:
    r3 <- as.data.frame(r2)

    haven't tried binary yet, while don't think it's possible because i feel MSRS uses toJSON on its output so that's why i need jsonlite::fromJSON() on the content of response. Please let me know if my guess is correct or not.

    Thursday, March 9, 2017 3:19 PM