Adding Package Libraries

Usage

add_lib(..., append = FALSE)

Arguments

...
paths to add to .libPath
append
logical that indicates that the paths should be appended rather than prepended.

Description

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

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/projects/pkgmaker" "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" [4] "/usr/lib/R/library"
show( .libPaths(tempdir()) )
[1] "/tmp/RtmpJ76dtL" "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" "/usr/lib/R/library"
# restore
.libPaths(ol)
# .libPaths does not keep the standard user library
show( .libPaths() )
[1] "/tmp/RtmpJ76dtL/file45b961b42189" "/home/renaud/Documents/projects/pkgmaker/pkg/lib" [3] "/home/renaud/R/i686-pc-linux-gnu-library/3.0" "/usr/local/lib/R/site-library" [5] "/usr/lib/R/site-library" "/usr/lib/R/library"
show( .libPaths('.') )
[1] "/home/renaud/Documents/projects/pkgmaker" "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" [4] "/usr/lib/R/library"
# restore
.libPaths(ol)
# with add_lib
show( add_lib('.') )
[1] "/home/renaud/Documents/projects/pkgmaker" "/tmp/RtmpJ76dtL/file45b961b42189" [3] "/home/renaud/Documents/projects/pkgmaker/pkg/lib" "/home/renaud/R/i686-pc-linux-gnu-library/3.0" [5] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" [7] "/usr/lib/R/library"
show( add_lib(tempdir()) )
[1] "/tmp/RtmpJ76dtL" "/home/renaud/Documents/projects/pkgmaker" [3] "/tmp/RtmpJ76dtL/file45b961b42189" "/home/renaud/Documents/projects/pkgmaker/pkg/lib" [5] "/home/renaud/R/i686-pc-linux-gnu-library/3.0" "/usr/local/lib/R/site-library" [7] "/usr/lib/R/site-library" "/usr/lib/R/library"
show( add_lib('..', append=TRUE) )
[1] "/tmp/RtmpJ76dtL" "/home/renaud/Documents/projects/pkgmaker" [3] "/tmp/RtmpJ76dtL/file45b961b42189" "/home/renaud/Documents/projects/pkgmaker/pkg/lib" [5] "/home/renaud/R/i686-pc-linux-gnu-library/3.0" "/usr/local/lib/R/site-library" [7] "/usr/lib/R/site-library" "/usr/lib/R/library" [9] "/home/renaud/Documents/projects"
# restore
.libPaths(ol)