问题
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.
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
The function is exported correctly (documentation using roxygen2):
> getNamespaceExports("MyPkg")
[1] "TestConnectivity"
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/
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
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.
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.
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.)
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.
回答1:
thanks for the answer (and the great work on OpenCPU, btw...)!
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.
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.
EDIT - I forgot: Of course, the url changes from /ocpu/library/MyPkg/R/
to /ocpu/user/MyUsername/library/MyPkg/R/
.
来源:https://stackoverflow.com/questions/25282741/custom-r-package-on-opencpu-package-found-but-no-functions-visible