Ubuntu – R and RStudio installation and package error

package-managementrrstudiosoftware installation

After installing R and RStudio in Ubuntu 16.04 with the following code:

sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev

and

sudo apt-get install gdebi-core
wget https://download1.rstudio.org/rstudio-1.0.143-amd64.deb
sudo gdebi rstudio-1.0.143-amd64.deb

I am trying to install packages and I am getting errors in R console like

install.packages("fGarch")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = "/usr/local/lib/R/site-library"' is not writable

As I am new in Linux I do not know in which directory install the R packages.
I am not sure whether this is the problem or if I did any mistake on the installation. Can anyone help me with this issue? Thanks in advance.

Best Answer

  • I don't know why R 3.4.1 changes the library path. To change it back, simply edit /etc/R/Renviron:

    $ sudo gedit /etc/R/Renviron
    

    Comment-out R_LIBS_SITE=... then uncomment R_LIBS_USER=...

    # edd Jun 2017  Comment-out R_LIBS_USER
    R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
    
    # edd Apr 2003  Allow local install in /usr/local, also add a directory for
    #               Debian packaged CRAN packages, and finally the default dir 
    # edd Jul 2007  Now use R_LIBS_SITE, not R_LIBS
    #R_LIBS_SITE=${R_LIBS_SITE-'/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library'}