Remove example packages


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)


  1. 'Package: fortunes, Path: /opt/R-libs/user, State: Not present'
  2. 'Package: fortunes, Path: /data/packages/R/x86_64-redhat-linux-gnu/3.4, State: Not present'

Environmental Variables

.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


'/opt/R-libs/user'

In [3]:
Sys.getenv('R_LIBS_USER') # Current shared R library folder


'/data/packages/R/x86_64-redhat-linux-gnu/3.4'

In [4]:
.libPaths() # Should include both paths give above


  1. '/data/packages/R/x86_64-redhat-linux-gnu/3.4'
  2. '/opt/R-libs/user'
  3. '/opt/R-libs/site'
  4. '/usr/lib64/R/library'

Install within the container


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


'/opt/R-libs/user/fortunes'

In [8]:
remove.packages('fortunes', lib='/opt/R-libs/user')

Install in shared library


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


Installing package into '/data/packages/R/x86_64-redhat-linux-gnu/3.4'
(as 'lib' is unspecified)

In [11]:
find.package('fortunes', quiet = TRUE) # Expected to return the install path to the shared folder


'/data/packages/R/x86_64-redhat-linux-gnu/3.4/fortunes'

In [12]:
remove.packages('fortunes')


Removing package from '/data/packages/R/x86_64-redhat-linux-gnu/3.4'
(as 'lib' is unspecified)

In [ ]: