Document how to install R packages as non-root user for use with Oracle R Connector for Hadoop (ORCH).
SOLUTION
Since Oracle R Distribution (ORD) is installed as root or sudo, this raises the question of how to install other R packages as non-root user?
R is meant to be a shared application, so that when packages are installed they will be placed in a global library and will be available for all users - the default is the global directory $R_HOME i.e. /usr/lib64/R. If you install as root or sudo, packages will be installed into $R_HOME/library. If you do not install packages as root you will not have permission to write packages into the global library directory i.e. $R_HOME/library and you will be prompted to create a personal library that is writable by your user id (and thus accessible to you only). Another option is to create another global directory writable by all R users. If the common directory is "/a/b/c", the syntax for setting .libPaths() is:
Setting .libPaths won't persist between R sessions, so it's common practice to place this in a .Rprofile or .Rprofile.site file thus it is executed each time R is started. (from within R see ?.libPaths for more information).
Steps to Install R Packages as Non-root:
1. Use the default non-root location provided by R to install your package. For example in Oracle Distribution of R version 2.15.1 that location is
Output when using default non-root location
Oracle Distribution of R version 2.15.1 (--) -- "Roasted Marshmallows"
...
> install.packages("png")
Installing package(s) into /usr/lib64/R/library
...
Warning in install.packages("png") :
'lib = "/usr/lib64/R/library"' is not writable
Would you like to use a personal library instead? (y/n) y
Would you like to create a personal library
~/R/x86_64-unknown-linux-gnu-library/2.15
to install packages into? (y/n) y
...
This installs the package into ~/R/x86_64-unknown-linux-gnu-library/2.15/<packagename>
To uninstall a package installed in this directory i.e. from R issue below command and package will be removed from the default location
2. Within R use .libPaths() to define your global path for example: .libPaths("/a/b/c")
$ R
...
> .libPaths("/a/b/c")
> install.packages("<package_name>")
Output using this case looks like:
Oracle Distribution of R version 2.15.1 (--) -- "Roasted Marshmallows"
...
> .libPaths("/a/b/c")
> install.packages("<package_name>")
Installing package(s) into "/a/b/c"
...
This installs the package into ("/a/b/c")
If you uninstall a package installed in the directory defined by .libPaths(), make sure to set .libPaths() before removing the package from R with:
3. Add the .libPaths() function to an existing .Rprofile/Rprofile.site file or create a new .Rprofile/Rprofile.site file if one does not already exist, by editing the file and adding for example:
Note that by default Rprofile.site is located at $R_HOME/etc/Rprofile.site. It is a site-wide R initialization file. .Rprofile is a local initialization file. R searches for a file called .Rprofile in the current directory or in the user home directory (in that order) and sources it into the user workspace.
Using a .Rprofile as an example:
...
.libPaths(c("/a/b/c",.libPaths()))
...
Output using this case looks like:
Oracle Distribution of R version 2.15.1 (--) -- "Roasted Marshmallows"
...
> install.packages("<package_name>")
Installing package(s) into "/a/b/c"
...
This installs the package into "/a/b/c" as set by .Rprofile.
If you uninstall a package installed in the directory defined by the .Rprofile, make sure the file exists before removing the package from R by issuing:
The same holds true if Rprofile.site is used.