devtools (version 1.9.1)

with_something: Execute code in temporarily altered environment.

Description

  • in_dir: working directory
  • with_collate: collation order
  • with_envvar: environmental variables
  • with_libpaths: library paths, replacing current libpaths
  • with_lib: library paths, prepending to current libpaths
  • with_locale: any locale setting
  • with_options: options
  • with_path: PATH environment variable
  • with_par: graphics parameters

Usage

with_envvar(new, code, action = "replace")

with_env(new, code)

with_locale(new, code)

with_collate(new, code)

in_dir(new, code)

with_libpaths(new, code)

with_lib(new, code)

with_options(new, code)

with_par(new, code)

with_path(new, code, add = TRUE)

with_makevars(new, code, path = file.path("~", ".R", "Makevars"))

Arguments

new
values for setting
code
code to execute in that environment
action
(for with_envvar only): should new values "replace", "suffix", "prefix" existing environmental variables with the same name.
add
Combine with existing values? Currently for with_path only. If FALSE all existing paths are ovewritten, which don't you usually want.
path
location of existing makevars to modify.

Deprecation

with_env will be deprecated in devtools 1.2 and removed in devtools 1.3

Details

If no existing makevars file exists or the fields in new do not exist in the existing Makevars file then the fields are added to the new file. Existing fields which are not included in new are appended unchanged. Fields which exist in Makevars and in new are modified to use the value in new.

Examples

Run this code
getwd()
in_dir(tempdir(), getwd())
getwd()

Sys.getenv("HADLEY")
with_envvar(c("HADLEY" = 2), Sys.getenv("HADLEY"))
Sys.getenv("HADLEY")

with_envvar(c("A" = 1),
  with_envvar(c("A" = 2), action = "suffix", Sys.getenv("A"))
)

Run the code above in your browser using DataLab