In [1]:
# Removes package ('fortune') from both container and shared libraries
examplePackages <- list(
list(name='fortunes', path=Sys.getenv('R_LIBS_SITE_USER')),
list(name='fortunes', path=Sys.getenv('R_LIBS_USER')))
clearPkg <- function(pkg) {
state <- 'Not present'
if(pkg$name %in% rownames(installed.packages(pkg$path))){
remove.packages(pkg$name, lib=pkg$path)
state <- 'Removed'
}
return(paste0('Package: ', pkg$name, ', Path: ', pkg$path, ', State: ', state))
}
lapply(examplePackages, clearPkg)
.libPaths
function lists the current paths available within R. In this example a path starting with /data/
will be a shared folder, other paths (eg /usr/
and /opt/
) reside within the container. The shared folder is defined by the environmental variable R_LIBS_USER
and the variable R_LIBS_SITE_USER
gives the user writable site folder.
In [2]:
Sys.getenv('R_LIBS_SITE_USER') # Current user writable container R path
In [3]:
Sys.getenv('R_LIBS_USER') # Current shared R library folder
In [4]:
.libPaths() # Should include both paths give above
In [5]:
find.package('fortunes', quiet = TRUE) # Expected to return nothing if package is not installed
In [6]:
install.packages('fortunes', lib = Sys.getenv('R_LIBS_SITE_USER'))
In [7]:
find.package('fortunes', quiet = TRUE) # Expected to return the install path to the user writable container folder
In [8]:
remove.packages('fortunes', lib='/opt/R-libs/user')
In [9]:
find.package('fortunes', quiet = TRUE) # Expected to return nothing if package is not installed
In [10]:
install.packages('fortunes') # Share location is the default install path
In [11]:
find.package('fortunes', quiet = TRUE) # Expected to return the install path to the shared folder
In [12]:
remove.packages('fortunes')
In [ ]: