r软件包开发-自己的功能对于opencpu不可见 [英] r package development - own function not visible for opencpu
问题描述
我刚开始编写R包.
r软件包开发导入未加载建议我使用roxygen2.
我曾经叫devtools::document()
并且生成了名称空间.
r package development imports not loaded advised me to use roxygen2.
I once called devtools::document()
and the namespace was generated.
但是,当我加载这个简单的程序包(或通过opencpu尝试)时,该功能不可用.
However when I load this simple package (or try it via opencpu) the functions are NOT available.
在本地R中调用代码似乎可行
calling the code in native R seems to work
test2::hello()
[1] "Hello, world!"
像这样启动opencpu:
Starting opencpu like:
1)通过library(opencpu)
2)执行opencpu$restart
,它将显示端口号
2) execute opencpu$restart
which will show a port number
3) http://localhost:myPortNumber/ocpu/library/myPackage/info --->此端点有效
3) http://localhost:myPortNumber/ocpu/library/myPackage/info ---> this endpoint works
如评论中所述,这不是调用函数的适当"方法.但是,如果通过HTTP作为http://public.opencpu.org/ocpu/library/stats/R/quantile/print
调用函数,则opencpu默认为myfunction/print
,即使当我调用hello函数时,该函数也不起作用.
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"
我确实通过sudo安装了它,
I did install it via sudo like:
sudo R CMD INSTALL test2_0.1.tgz
意味着它应该在/library/test2
端点中可以使用.
that means it should be available via in the /library/test2
endpoint.
它仍然是错误的API端点->我缺少R子目录
It still was the wrong API endpoint --> I was missing the R sub-directory
http://localhost:myPort/ocpu/library/myPackage/R/hello/
示例代码在这里: https://github.com/geoHeil/rSimplePackageForOpenCpu >
Example-code is here: https://github.com/geoHeil/rSimplePackageForOpenCpu
推荐答案
它仍然是错误的API端点->我缺少R子目录
It still was the wrong API endpoint --> I was missing the R sub-directory
http://localhost:myPort/ocpu/library/myPackage/R/hello/
这篇关于r软件包开发-自己的功能对于opencpu不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!