Debian Codegraph @

man/with_package.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/namespace.R
3 \name{with_package}
4 \alias{with_package}
5 \alias{local_package}
6 \alias{with_namespace}
7 \alias{local_namespace}
8 \alias{with_environment}
9 \alias{local_environment}
10 \title{Execute code with a modified search path}
11 \usage{
12 with_package(
13 package,
14 code,
15 pos = 2,
16 lib.loc = NULL,
17 character.only = TRUE,
18 logical.return = FALSE,
19 warn.conflicts = FALSE,
20 quietly = TRUE,
21 verbose = getOption("verbose")
22 )
23
24 local_package(
25 package,
26 pos = 2,
27 lib.loc = NULL,
28 character.only = TRUE,
29 logical.return = FALSE,
30 warn.conflicts = FALSE,
31 quietly = TRUE,
32 verbose = getOption("verbose"),
33 .local_envir = parent.frame()
34 )
35
36 with_namespace(package, code, warn.conflicts = FALSE)
37
38 local_namespace(package, .local_envir = parent.frame(), warn.conflicts = FALSE)
39
40 with_environment(
41 env,
42 code,
43 pos = 2L,
44 name = format(env),
45 warn.conflicts = FALSE
46 )
47
48 local_environment(
49 env,
50 pos = 2L,
51 name = format(env),
52 warn.conflicts = FALSE,
53 .local_envir = parent.frame()
54 )
55 }
56 \arguments{
57 \item{package}{\code{[character(1)]}\cr package name to load.}
58
59 \item{code}{\code{[any]}\cr Code to execute in the temporary environment}
60
61 \item{pos}{the position on the search list at which to attach the
62 loaded namespace. Can also be the name of a position on the current
63 search list as given by \code{\link[base]{search}()}.}
64
65 \item{lib.loc}{a character vector describing the location of \R
66 library trees to search through, or \code{NULL}. The default value
67 of \code{NULL} corresponds to all libraries currently known to
68 \code{\link[base]{.libPaths}()}.
69 Non-existent library trees are silently ignored.}
70
71 \item{character.only}{a logical indicating whether \code{package} or
72 \code{help} can be assumed to be character strings.}
73
74 \item{logical.return}{logical. If it is \code{TRUE}, \code{FALSE} or
75 \code{TRUE} is returned to indicate success.}
76
77 \item{warn.conflicts}{logical. If \code{TRUE}, warnings are
78 printed about \code{\link[base]{conflicts}} from attaching the new
79 package. A conflict is a function masking a function,
80 or a non-function masking a non-function. The default is \code{TRUE}
81 unless specified as \code{FALSE} in the \code{conflicts.policy} option.
82 }
83
84 \item{quietly}{a logical. If \code{TRUE}, no message confirming
85 package attaching is printed, and most often, no errors/warnings are
86 printed if package attaching fails.}
87
88 \item{verbose}{a logical. If \code{TRUE}, additional diagnostics are
89 printed.}
90
91 \item{.local_envir}{\verb{[environment]}\cr The environment to use for scoping.}
92
93 \item{env}{\code{[environment()]}\cr Environment to attach.}
94
95 \item{name}{name to use for the attached database. Names starting with
96 \code{package:} are reserved for \code{\link[base]{library}}.}
97 }
98 \value{
99 \code{[any]}\cr The results of the evaluation of the \code{code}
100 argument.
101 }
102 \description{
103 \code{with_package()} attaches a package to the search path, executes the code, then
104 removes the package from the search path. The package namespace is \emph{not}
105 unloaded however. \code{with_namespace()} does the same thing, but attaches the
106 package namespace to the search path, so all objects (even unexported ones) are also
107 available on the search path.
108 }
109 \examples{
110 \dontrun{
111 with_package("ggplot2", {
112 ggplot(mtcars) + geom_point(aes(wt, hp))
113 })
114 }
115 }
116 \seealso{
117 \code{\link{withr}} for examples
118 }