A few R packages are “installed” in a tmp library but I they can't be found using library(“package”)?

ggplot2
r
linux
package-installation
ubuntu

#1

When I open sudo R into the terminal and try, for instance, install "ggplot2", the terminal/rstudio returns with this message.

 installing to /home/gui/R/x86_64-pc-linux-gnu-library/3.5/mgcv/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
Error: package or namespace load failed for ‘nlme’:
 package ‘nlme’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version
Error : package ‘nlme’ could not be loaded
ERROR: lazy loading failed for package ‘mgcv’
* removing ‘/home/gui/R/x86_64-pc-linux-gnu-library/3.5/mgcv’
ERROR: dependency ‘mgcv’ is not available for package ‘ggplot2’
* removing ‘/home/gui/R/x86_64-pc-linux-gnu-library/3.5/ggplot2’

The downloaded source packages are in
    ‘/tmp/RtmpRyAmBn/downloaded_packages’
Warning messages:
1: In install.packages("ggplot2") :
  installation of package ‘mgcv’ had non-zero exit status
2: In install.packages("ggplot2") :
  installation of package ‘ggplot2’ had non-zero exit status 

And when I put library("ggplot2") the output:

library("ggplot2") Error in library("ggplot2") : there is no package called ‘ggplot2’


#2

Did you update R version from 3.4.x to 3.5.x recently? One of the errors tells you that nlme package has been installed for older version, so it should be reinstalled in newer. And as you can read from the error messages, ggplot2 hasn't been installed successfully because of that.
So, you need to first run install.packages("nlme") and all other packages that fail with this error.


#3

Just as a note, R puts this line at the end of many installations (both successful and not). During installation, R first stores what it downloaded from CRAN in a randomly generated temporary file location. Then it uses those downloaded files to install the package into your library (depending on the package, this can mean just copying it over largely unchanged, or it can mean executing a complex build process).

So the line above is just a courtesy message letting you know where to find the files R initially downloaded from the repository, in case you want to do something with them. In the vast majority of cases, you will not want to do anything with them and can ignore this message! :grin: