Thursday, November 14, 2013

Install R Package without access as root

Operate R under unix system that means you are merely a single user on this SUPER computer. As a unix rookie ( ya indeed I am ) I didn't know I can't install R package but through the root access. Fortunately, I still find a way to go through it on google it!

Check your R to find the path of the R library

> .libPaths()
"/usr/lib/R/library"  "/usr/share/R/library"

This is what appears originally. Then you can make some adjustment with the path of library first, suppose you did install package through

$R CMD INSTALL -l lib/R lib/'packagename'.tar.gz

then it is instantly install in your predestined folder

/lib/R

Then in that folder you have your package to be installed. In case of that, do this in R

> library(packagename, lib.loc="~/lib/R")

Then it's done! Otherwise, there is another way by change the R_LIB in ./cshrc (or ./bashrc) by edit the alias in ./cshrc by the following

if ($?R_LIBS) then
   setenv R_LIBS~/lib/R:$R_LIBS
else
   setenv R_LIBS~/lib/R
endif 

And then source the new edited ./cshrc then

> .libPaths()
"~/lib/R" "/usr/lib/R/library"  "/usr/share/R/library"

you are done!



No comments: