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.