config R libPath in ubuntu

by specify lib

Posted by Yuan on July 7, 2022

After install R,and Rstudio-desktop in ubuntu, I’m trying to work under ubuntu to analyze previous pending jobs. When, installing the required packages in Rstudio, I got the “installationpath not writable,unable to update packages” info.

Based on the solution provided in itecnote, I could install by specify the place I want the packages to be installed. If I had the admin right, I could also remove the old packages.

Install packages by specify installation lib

1
2
3
4
5
6
7
8
.libPaths()
#[1] "/home/xxx/R/x86_64xxxx-library/4.2"
#[2] "/usr/local/lib/R/site-library"
#[3] "/usr/lib/R/site-library"
#[4] "/usr/lib/R/library"
install.packages(c("PKG1", "PKG2", "PKG3"),lib = "/home/USER/R/x86_64-pc-linux-gnu-library/X.X") 
BiocManager::install(c("PKG1", "PKG2", "PKG3"),lib = "/home/USER/R/x86_64-pc-linux-gnu-library/X.X")

Remove old lib

We could either remove the older package folders with “sudo rm -rf PKG1”. Or we could run R with administrator right, and run remove.package by specifying the place hold the old packages.

1
2
#Run R with Administation right
remove.packages(c("PKG1", "PKG2", "PKG3"), lib = "/usr/lib/R/library")