library.loc: Load package (and dependencies) from specified directory.

Description Usage Arguments Examples

Description

This function reassigns .libPaths() to the specified directory then tries to load the package using base::library. This is to ensure that package depenedencies (and the package itself) are not loaded from other directories in the search tree (.libPaths()).

Usage

1
library.loc(pkg, loc, ...)

Arguments

loc

directory to load from.

...

other arguments to pass to base::library.

package

name of package to load.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
cwd <- getwd()

dir1 <- paste0(cwd, "/dir1")
dir2 <- paste0(cwd, "/dir2")

dir.create(dir1)
dir.create(dir2)

# install gbm package with and without dependencies
install.packages("gbm", lib = dir1, dependencies = c("Depends", "Imports"))
install.packages("gbm", lib = dir2, dependencies = FALSE)

# try to load from the directory without dependencies
library.loc(gbm, loc = dir2)

# now try to load from the directory with dependencies installed
library.loc(gbm, loc = dir1)

# to see behaviour of base::library - restart R before running
.libPaths(c(dir1, dir2))
library(gbm, lib.loc = dir2)

richardangell/library.loc documentation built on May 27, 2019, 7:40 a.m.