install R package without root access(on Linux)

R is a nice compannon for stataitical people.From time to time, I have to install various packages to accomplish some tasks. At my desktop (linux server), I have the root access, the installation is pretty simple,

R packages can be downloaded here

[Date order] [Name ordered]

Start R console and fire the installation command,

sudo R

>install.packages(“boa”)

or you can download the package and install it using the command line

sudo R CMD INSTALL boa_1.1.7-2.tar.gz

When working at other server, apparently, I have no root access,  have to install packages at my home dir

make a R local dir, download the package and install it

mkdir ~/myRdir

R CMD INSTALL ctv.tar.gz -l $HOME/myRdir

to use it, you have to defined R_LIB environmental variable, I put it at ~/.bashrc

R_LIBS=/home/USER/R
export R_LIBS

then load it is you need as

library(“boa”)

Happy R!

About these ads

4 responses to “install R package without root access(on Linux)

  1. I have used R in Windows for a couple of years, but I just started using R in Linux recently. I followed your instructions above and was able to load the boa package using the install.packages(“boa”) command. I tried the same command with a couple different packages and got error messages:

    > install.packages(“stringr”)
    Warning message:
    In getDependencies(pkgs, dependencies, available, lib) :
    package âstringrâ is not available (for R version 2.13.1)

    Can you give me any advice? Note: I am working remotely via SSH on a Linux machine.

    • not sure why, it works for me. here is the output fyi
      ps you may have define contriburl or repos in the install.packages()
      good luck

      repos: character vector, the base URLs of the repositories to use,
      e.g., the URL of a CRAN mirror such as
      ‘”http://cran.us.r-project.org”’.

      Can be ‘NULL’ to install from local files (with extension
      ‘.tar.gz’ for source packages).

      contriburl: URL(s) of the contrib sections of the repositories. Use
      this argument only if your repository mirror is incomplete,
      e.g., because you burned only the ‘contrib’ section on a CD.
      Overrides argument ‘repos’. As with ‘repos’, can also be
      ‘NULL’ to install from local files.

      install.packages(‘stringr’)
      Installing package(s) into ‘/usr/local/lib/R/site-library’
      (as ‘lib’ is unspecified)
      Warning in install.packages(“stringr”) :
      ‘lib = “/usr/local/lib/R/site-library”‘ is not writable
      Would you like to create a personal library
      ~/R/i686-pc-linux-gnu-library/2.14
      to install packages into? (y/n) y
      — Please select a CRAN mirror for use in this session —
      Loading Tcl/Tk interface … done
      also installing the dependency ‘plyr’

      trying URL ‘http://cran.ms.unimelb.edu.au/src/contrib/plyr_1.7.1.tar.gz’
      Content type ‘application/x-tar’ length 367683 bytes (359 Kb)
      opened URL
      ==================================================
      downloaded 359 Kb

      trying URL ‘http://cran.ms.unimelb.edu.au/src/contrib/stringr_0.6.tar.gz’
      Content type ‘application/x-tar’ length 20551 bytes (20 Kb)
      opened URL
      ==================================================
      downloaded 20 Kb

      * installing *source* package ‘plyr’ …
      ** package ‘plyr’ successfully unpacked and MD5 sums checked
      ** libs
      gcc -std=gnu99 -I/usr/share/R/include -fpic -O3 -pipe -g -c loop-apply.c -o loop-apply.o
      gcc -std=gnu99 -I/usr/share/R/include -fpic -O3 -pipe -g -c split-numeric.c -o split-numeric.o
      gcc -std=gnu99 -shared -o plyr.so loop-apply.o split-numeric.o -L/usr/lib/R/lib -lR
      installing to /home/yuandan/R/i686-pc-linux-gnu-library/2.14/plyr/libs
      ** R
      ** data
      ** moving datasets to lazyload DB
      ** inst
      ** preparing package for lazy loading
      ** help
      *** installing help indices
      ** building package indices …
      ** testing if installed package can be loaded

      * DONE (plyr)
      * installing *source* package ‘stringr’ …
      ** package ‘stringr’ successfully unpacked and MD5 sums checked
      ** R
      ** inst
      ** preparing package for lazy loading
      ** help
      *** installing help indices
      ** building package indices …
      ** testing if installed package can be loaded

      * DONE (stringr)

      The downloaded packages are in
      ‘/tmp/RtmpUs46u6/downloaded_packages’

  2. Pingback: Installing R on Debian – 64-bit? | mongopi·

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s