r package development - own function not visible for opencpu

为君一笑 提交于 2020-01-16 01:19:09

问题


Hi I am new to writing R packages.

r package development imports not loaded advised me to use roxygen2. I once called devtools::document() and the namespace was generated.

However when I load this simple package (or try it via opencpu) the functions are NOT available.

calling the code in native R seems to work

test2::hello()
[1] "Hello, world!"

Starting opencpu like:

1) start opencpu simple server via library(opencpu)

2) execute opencpu$restartwhich will show a port number

3) http://localhost:myPortNumber/ocpu/library/myPackage/info ---> this endpoint works

As mentioned in the comments this is not a "proper" way of calling a function. However opencpu defaults to myfunction/print if a function is called via HTTP as http://public.opencpu.org/ocpu/library/stats/R/quantile/printand even that does not work when I call the hello function.

This is a demonstration of how to call a more complex function:

curl http://localhost:myPortNumber/ocpu/library/stats/R/quantile/json -d '{"type":1,"x":[1,2,3,4,5,6,7,8,9,10],"probs":[0.05,0.25,0.75,0.95]}' -H "Content-Type: application/json"

You can simply test it via:

curl http://public.opencpu.org/ocpu/library/stats/R/quantile/json -d \
'{"type":1,"x":[1,2,3,4,5,6,7,8,9,10],"probs":[0.05,0.25,0.75,0.95]}' \
-H "Content-Type: application/json"

I did install it via sudo like:

sudo R CMD INSTALL test2_0.1.tgz

that means it should be available via in the /library/test2 endpoint.

Solution:

It still was the wrong API endpoint --> I was missing the R sub-directory

http://localhost:myPort/ocpu/library/myPackage/R/hello/

Example-code is here: https://github.com/geoHeil/rSimplePackageForOpenCpu


回答1:


It still was the wrong API endpoint --> I was missing the R sub-directory

http://localhost:myPort/ocpu/library/myPackage/R/hello/


来源:https://stackoverflow.com/questions/30720340/r-package-development-own-function-not-visible-for-opencpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!