unable to access R packages under user account in opencpu
Asked Answered
S

1

6

I am trying to access R packages which were installed under a user's account from opencpu. I can see that the package is installed when I start R as that user:

> installed.packages() 
           Package      LibPath                                         
RLIM       "RLIM"       "/limdata/ali/R/x86_64-pc-linux-gnu-library/3.0"
...
> system('whoami');
ali

However, when I try to access the library from opencpu, I get errors indicating the package was not found:

$ curl -L http://<my.server>/ocpu/user/ali/library/RLIM
there is no package called 'RLIM'

In call:
find.package(pkgname, lib.loc = lib.loc)
# from same server, to confirm opencpu is running... 
$ curl -L http://<my.server>/ocpu/library 
base
bitops
boot
brew
...

Any help would be greatly appreciated!

Platform info:

  • Host: Ubuntu 12.04
  • opencpu-server 1.0.4-precise0
  • opencpu-lib: 1.0.4-precise0
  • R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Spirketing answered 17/10, 2013 at 15:42 Comment(0)
F
1

It seems like your home library is not in the default location of /home/ali/. Therefore some additional steps are needed to access your packages.

First of all, the default security profile won't allow OpenCPU to access /limdata/. To verify that this is indeed the problem, have a look at /var/log/kern.log and search for lines containing APPARMOR and DENIED. Please read the section titled Customizing the security profile in the PDF server manual.

To add your home library to the security profile, edit /etc/apparmor.d/opencpu.d/custom and add these lines:

/limdata/ r,
/limdata/** mrix,

Afterwards, restart apparmor and opencpu:

 sudo service apparmor restart
 sudo service opencpu restart

That should take care of the security restrictions. I hope that will do it; honestly I haven't tested a scenario where the home directory is outside of /home but I think if your R_LIBS_USER environment variable is properly configured, it should work. If not let me know :-)

Floydflss answered 17/10, 2013 at 18:39 Comment(5)
Thank you for your prompt response! I did not see any DENIED entries in kern.log. Editing /etc/apparmor.d/opencpu.d/custom and restarting apparmor and opencpu did not resolve the issue. However, it was peculiar that when I issued GET on /ocpu/user resource, the only user listed was the one whose home was under /home. I added a new user under /home and I can see the users home library. I will try to dig further into R_LIBS_USER and post my findings. Thanks again for the help!Spirketing
I think I know whats causing the issue. The userhome() function in userlibpath.R returns '/home' if the effective user is root or www-data which is what the apache process is running as. So the function userlibpath executed as either user root or www-data returns "/home/ali/R/x86_64-pc-linux-gnu-library/3.0" which is incorrect while running the same function as user 'ali' returns the correct path: "/limdata/ali/R/x86_64-pc-linux-gnu-library/3.0"Spirketing
Yes you are right. If you would like to suggest a more robust way of detecting user home dir, send a pull request :-) Perhaps a temporary workaround would be to make a symlink from /home/ali to /limdata/ali ?Floydflss
Send me a email if you'd like to help get this fixed in the next version.Floydflss
@AliGuler @Jeroen How did you solve this problem? My home directory is /home/deploy where ~/R/library is located. From ~/.Renviron I point to R_LIBS_USER=~/R/library. Also tried R_LIBS. No Luck.Strathspey

© 2022 - 2024 — McMap. All rights reserved.