OpenCPU上的自定义R包/找到包,但是看不到任何功能 [英] Custom R package on OpenCPU / Package found, but no functions visible

查看:120
本文介绍了OpenCPU上的自定义R包/找到包,但是看不到任何功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CI已为OpenCPU编写了R软件包,并希望在我自己的Cloud服务器上使用它.即使可以识别包本身并可以对其进行更新,我也无法访问任何功能,而且我通常可以通过POST和GET访问其他(非定制的,例如基本或统计信息)包.

CI have written an R package for OpenCPU and want to use it on my own Cloud server. I cannot access any functions even though the package itself is recognized and can be updated, and I can access other (non-custom, e.g. base or stats) packages normally via POST and GET.

我已经安装了自定义程序包以及对/usr/local/lib/R/site-library的所有依赖关系,并且可以在服务器本地的R会话中使用这些功能.

I have installed the custom package together with all dependencies to /usr/local/lib/R/site-library and I can use the functions from within an R session locally on the server.

> TestConnectivity
function (x = 100) 
{
    return(sum(rnorm(x)))
}
<environment: namespace:MyPkg>
> TestConnectivity()
[1] 4.174071

该函数已正确导出(使用roxygen2的文档):

The function is exported correctly (documentation using roxygen2):

> getNamespaceExports("MyPkg")
[1] "TestConnectivity"

但是当我在/ocpu/library/MyPkg/R/TestConnectivity上通过OpenCPU(通过浏览器或通过curl)访问它时,我得到:

but when I access it via OpenCPU (either through the browser or through curl) at /ocpu/library/MyPkg/R/TestConnectivity, I get:

object 'TestConnectivity' not found

In call:
get(reqobject, paste("package", reqpackage, sep = ":"), inherits = FALSE)

/ocpu/library/MyPkg/R/也为空白(通常需要导出的功能列表),但该包本身可通过浏览器在/ocpu/library/MyPkg/处看到:

/ocpu/library/MyPkg/R/ is blank as well (normally, a list of exported functions is expected), but the package itself is visible via browser at /ocpu/library/MyPkg/:

    Information on package 'MyPkg'

Description:

Package:       MyPkg
Description:   in development ...
Type:          Package
Version:       0.1.2
[...]

Index:

TestConnectivity        Test Connectivity of OpenCPU
MyPkg                   Provide R analysis of stored data.
MyPkg-package           Calculation package

我已将其名称添加到/etc/opencpu/server.conf中的preload字段中,但/ocpu/info仅将其显示为loaded via a namespace (and not attached): [n] MyPkg_0.1.2.我不知道这是否有问题.

I have added its name to the preload field in /etc/opencpu/server.conf, but /ocpu/info only shows it as loaded via a namespace (and not attached): [n] MyPkg_0.1.2. I don't know, if that's a problem.

我还为/etc/apparmor.d/opencpu.d/custom添加了软件包功能所需的所有文件的访问权限,例如ODBC数据库连接的DSN配置文件.

I also have added access rights to all files necessary for the package's functionality to /etc/apparmor.d/opencpu.d/custom, e.g. the DSN config files for an ODBC database connection.

程序包本身不仅由功能组成,而且还由组合的R6S3类定义(单个文件中的继承性)组成-尽管如此,在TestConnectivity()中都不使用这些定义.这些功能也并非总是放在与该功能名称完全相同的文件中-有时将多个功能组合到一个文件中. (TestConnectivity()放在相应的TestConnectivity.R文件中-如果需要的话.)

The package itself consists not only of functions, but also of assembled R6 and S3 class definitions (inheritance within single files) - none of which are used within TestConnectivity(), nevertheless. The functions are also not always placed in files with the exact same name as the function - and sometimes several are combined in one file. (TestConnectivity() is placed within the corresponding TestConnectivity.R file - if it matters.)

与在本地使用软件包相比,使用OpenCPU时是否对文件结构有一些限制?还是类定义文件可能会引起麻烦?任何建议表示赞赏.

Is there some constraint regarding the file structure when using OpenCPU in contrast to using a package locally, which might cause this problem? Or could the class definition files be the cause of the trouble? Any suggestions are appreciated.

推荐答案

感谢您的回答(以及有关OpenCPU的出色工作,顺便说一句...)!

thanks for the answer (and the great work on OpenCPU, btw...)!

我通过简单地将软件包安装在/home/myUser/R/3.1/library中来解决了我的问题,例如.libPaths()[1](或R-LIBS-USER[1])而不是/usr/local/lib/R/site-library.

I solved my issue by simply installing the package in /home/myUser/R/3.1/library, e.g. .libPaths()[1] (or R-LIBS-USER[1]) instead of /usr/local/lib/R/site-library.

我通过逐步建立越来越复杂的测试包而到达了那里...在我几乎拥有实际项目的结构的那一刻,它仍然有效.唯一的区别是安装路径.

I got there by incrementally building up a more and more complex test package... and at the point where I nearly had the structure of my actual project, it still worked. Only difference was the installation path.

总而言之,这可能是我的虚拟机而不是OpenCPU或程序包上的权限管理问题.很抱歉,我无法提供更多信息-如果我偶然发现某些内容,请在此处添加.

All in all it's probably an issue with the rights-management on my virtual machine rather than with OpenCPU or my package. I am sorry that I cannot provide more information - if I stumble onto something, I will add it here.

编辑-我忘记了:当然,URL从/ocpu/library/MyPkg/R/更改为/ocpu/user/MyUsername/library/MyPkg/R/.

EDIT - I forgot: Of course, the url changes from /ocpu/library/MyPkg/R/ to /ocpu/user/MyUsername/library/MyPkg/R/.

这篇关于OpenCPU上的自定义R包/找到包,但是看不到任何功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆