Most of the libraries I use in R are installed via the OS (i.e. using apt install r-cran-*
which are installed in /usr/lib/R/*
). Unfortuntaely, when using update.libraries()
within a session offers to update these packages'm trying to have R only install libraries in specific locations. As a result, I've tried modifying my .Rprofile in the following manner:
## only update libraries installed in R sessions.
## Don't update libraries installed using apt.
## these libraries reside in /usr/lib/R
## Code based on: https://coolbutuseless.github.io/2018/04/11/changing-the-default-arguments-to-a-function/
library(default)
## See my note on stackexchange how this doesn't work as expected
## default(update.packages) <- list(lib.loc=grep("/usr/lib/R", .libPaths(), invert=TRUE, value=TRUE))
tmpUser = Sys.getenv("USER")
if( tmpUser =="root"){
tmpLibPath <- "/usr/local/lib/R/site-library"
}else{
tmpLibPath <- Sys.getenv("R_LIBS_USER")
}
default(update.packages) <- list(lib.loc = tmpLibPath)
default(install.packages) <- list(lib = tmpLibPath)
## Clean up
rm(c("tmpUser", "tmpLibPath")
However, when I start an R session, I get the error,
`Error in default(update.packages) <- list(lib.loc = tmpLibPath) : object 'update.packages' not found
and my changes don't stick (though they do if I execute the code within an interactive session). Can anyone help me either (a) understand what I'm doing wrong or (b) suggest another way to achieve this goal?