Search code examples
opencpu

Calling opencpu custom function returns error


I uploaded a function (apistatus5) into an opencpu store (ropensci_dash):

https://public.opencpu.org/R/user/SChamberlain/ropensci_dash/apistatus5/ascii

I put the function into a store within opencpu under my username (SChamberlain), but I keep getting the error:

STRING_ELT() can only be applied to a 'character vector', not a 'raw'

Is there some kind of bug detection for opencpu? The code works fine on my own machine within R, so I am not sure where the bug is when trying to run using:

https://public.opencpu.org/R/user/SChamberlain/ropensci_dash/apistatus5/png


Solution

  • Thanks, this is interesting. I am getting the same error on my local R:

    Error in rjson::fromJSON(httr::content(httr::GET("http://api.plos.org/search?q=id:10.1371/journal.pbio.0000012&wt=json"))) : 
    STRING_ELT() can only be applied to a 'character vector', not a 'raw'
    

    The httr::content function by default returns a raw vector, which fromJSON doesn't like. If you are not getting this error, this is most likely is due to different versions of the R packages (rjson or httr) on the server than on your local machine. I think you need to update httr and replace content by text_content. Also RJSONIO package is a bit better than rjson I think.

    However, I realize this is very hard to debug. I have to think about this a bit how to improve this.