Prepend/append paths to the library path list, using .libPaths.

add_lib(..., append = FALSE)

Arguments

...

paths to add to .libPath

append

logical that indicates that the paths should be appended rather than prepended.

Details

This function is meant to be more convenient than .libPaths, which requires more writing if one wants to:

  • sequentially add libraries;

  • append and not prepend new path(s);

  • keep the standard user library in the search path.

Examples

ol <- .libPaths() # called sequentially, .libPaths only add the last library show( .libPaths('.') )
#> [1] "/home/renaud/Documents/R-packages/pkgmaker/docs/reference" #> [2] "/usr/local/lib/R/site-library" #> [3] "/usr/lib/R/site-library" #> [4] "/usr/lib/R/library"
show( .libPaths(tempdir()) )
#> [1] "/tmp/RtmpIQNZAJ" "/usr/local/lib/R/site-library" #> [3] "/usr/lib/R/site-library" "/usr/lib/R/library"
# restore .libPaths(ol) # .libPaths does not keep the standard user library show( .libPaths() )
#> [1] "/tmp/RtmpJs7h8M/temp_libpath75ed85ee0ea45" #> [2] "/home/renaud/R/x86_64-pc-linux-gnu-library/4.0" #> [3] "/usr/local/lib/R/site-library" #> [4] "/usr/lib/R/site-library" #> [5] "/usr/lib/R/library"
show( .libPaths('.') )
#> [1] "/home/renaud/Documents/R-packages/pkgmaker/docs/reference" #> [2] "/usr/local/lib/R/site-library" #> [3] "/usr/lib/R/site-library" #> [4] "/usr/lib/R/library"
# restore .libPaths(ol) # with add_lib show( add_lib('.') )
#> [1] "/home/renaud/Documents/R-packages/pkgmaker/docs/reference" #> [2] "/tmp/RtmpJs7h8M/temp_libpath75ed85ee0ea45" #> [3] "/home/renaud/R/x86_64-pc-linux-gnu-library/4.0" #> [4] "/usr/local/lib/R/site-library" #> [5] "/usr/lib/R/site-library" #> [6] "/usr/lib/R/library"
show( add_lib(tempdir()) )
#> [1] "/tmp/RtmpIQNZAJ" #> [2] "/home/renaud/Documents/R-packages/pkgmaker/docs/reference" #> [3] "/tmp/RtmpJs7h8M/temp_libpath75ed85ee0ea45" #> [4] "/home/renaud/R/x86_64-pc-linux-gnu-library/4.0" #> [5] "/usr/local/lib/R/site-library" #> [6] "/usr/lib/R/site-library" #> [7] "/usr/lib/R/library"
show( add_lib('..', append=TRUE) )
#> [1] "/tmp/RtmpIQNZAJ" #> [2] "/home/renaud/Documents/R-packages/pkgmaker/docs/reference" #> [3] "/tmp/RtmpJs7h8M/temp_libpath75ed85ee0ea45" #> [4] "/home/renaud/R/x86_64-pc-linux-gnu-library/4.0" #> [5] "/usr/local/lib/R/site-library" #> [6] "/usr/lib/R/site-library" #> [7] "/usr/lib/R/library" #> [8] "/home/renaud/Documents/R-packages/pkgmaker/docs"
# restore .libPaths(ol)