问题
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$restart
which 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/print
and 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