Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #215 from wch/with-lib

Add with_lib function. Fixes #183
  • Loading branch information...
commit 22477fa2198f28cb1eddb8659d5fc3d6af6761a1 2 parents a5099b0 + 5057d8e
@wch wch authored
Showing with 30 additions and 6 deletions.
  1. +1 −0  NAMESPACE
  2. +4 −0 NEWS
  3. +16 −1 R/with.r
  4. +9 −5 man/with_something.Rd
View
1  NAMESPACE
@@ -65,6 +65,7 @@ export(wd)
export(with_collate)
export(with_debug)
export(with_env)
+export(with_lib)
export(with_libpaths)
export(with_locale)
export(with_options)
View
4 NEWS
@@ -25,6 +25,10 @@ MINOR FEATURES
* `install_bitbucket()` now always uses lowercase repo names. (Thanks to mnel)
+* New function `with_lib()`, which runs an expression code with a library path
+ prepended to the existing libpaths. It differs slightly from
+ `with_libpaths()`, which replaces the existing libpaths.
+
BUG FIXES
* Fixed path issue when looking for Rtools on windows when registry entry is not present. (Fixes #201)
View
17 R/with.r
@@ -4,7 +4,8 @@
#' \item \code{in_dir}: working directory
#' \item \code{with_collate}: collation order
#' \item \code{with_env}: environmental variables
-#' \item \code{with_libpaths}: library paths
+#' \item \code{with_libpaths}: library paths, replacing current libpaths
+#' \item \code{with_lib}: library paths, prepending to current libpaths
#' \item \code{with_locale}: any locale setting
#' \item \code{with_options}: options
#' \item \code{with_path}: PATH environment variable
@@ -94,6 +95,20 @@ set_libpaths <- function(paths) {
#' @export
with_libpaths <- with_something(set_libpaths)
+# lib ------------------------------------------------------------------------
+
+set_lib <- function(paths) {
+ libpath <- normalizePath(paths, mustWork = TRUE)
+
+ old <- .libPaths()
+ .libPaths(c(libpath, .libPaths()))
+ invisible(old)
+}
+
+#' @rdname with_something
+#' @export
+with_lib <- with_something(set_lib)
+
# options --------------------------------------------------------------------
#' @rdname with_something
View
14 man/with_something.Rd
@@ -2,6 +2,7 @@
\alias{in_dir}
\alias{with_collate}
\alias{with_env}
+\alias{with_lib}
\alias{with_libpaths}
\alias{with_locale}
\alias{with_options}
@@ -20,6 +21,8 @@
with_libpaths(new, code)
+ with_lib(new, code)
+
with_options(new, code)
with_par(new, code)
@@ -40,11 +43,12 @@
\itemize{ \item \code{in_dir}: working directory \item
\code{with_collate}: collation order \item
\code{with_env}: environmental variables \item
- \code{with_libpaths}: library paths \item
- \code{with_locale}: any locale setting \item
- \code{with_options}: options \item \code{with_path}: PATH
- environment variable \item \code{with_par}: graphics
- parameters }
+ \code{with_libpaths}: library paths, replacing current
+ libpaths \item \code{with_lib}: library paths, prepending
+ to current libpaths \item \code{with_locale}: any locale
+ setting \item \code{with_options}: options \item
+ \code{with_path}: PATH environment variable \item
+ \code{with_par}: graphics parameters }
}
\examples{
getwd()
Please sign in to comment.
Something went wrong with that request. Please try again.