File: temp_env.Rd

package info (click to toggle)
r-cran-svmisc 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: sh: 12; makefile: 2
file content (153 lines) | stat: -rw-r--r-- 4,158 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/temp_env.R
\name{temp_env}
\alias{temp_env}
\alias{add_items}
\alias{add_temp}
\alias{assign_temp}
\alias{change_temp}
\alias{exists_temp}
\alias{get_temp}
\alias{delete_temp}
\alias{rm_temp}
\alias{TempEnv}
\alias{addItems}
\alias{addTemp}
\alias{assignTemp}
\alias{changeTemp}
\alias{existsTemp}
\alias{getTemp}
\alias{rmTemp}
\title{Get an environment dedicated to temporary variables (and create it if needed)}
\usage{
temp_env()

add_items(x, y, use.names = TRUE, replace = TRUE)

add_temp(x, item, value, use.names = TRUE, replace = TRUE)

assign_temp(x, value, replace.existing = TRUE)

change_temp(x, item, value, replace.existing = TRUE)

exists_temp(x, mode = "any")

get_temp(x, default = NULL, mode = "any", item = NULL)

delete_temp(x)

rm_temp(x)

TempEnv()

addItems(x, y, use.names = TRUE, replace = TRUE)

addTemp(x, item, value, use.names = TRUE, replace = TRUE)

assignTemp(x, value, replace.existing = TRUE)

changeTemp(x, item, value, replace.existing = TRUE)

existsTemp(x, mode = "any")

getTemp(x, default = NULL, mode = "any", item = NULL)

rmTemp(x)
}
\arguments{
\item{x}{The vector to add items to for \code{add_items()} or any object. for
\code{delete_temp()}, it is the name of the variable (character string), or a
vector of characters with the name of all variables to remove from
\code{SciViews:TempEnv}.}

\item{y}{The vector of which we want to inject missing items in 'x'.}

\item{use.names}{Use names of items to determine which one is unique,
otherwise, the selection is done on the items themselves.}

\item{replace}{Do we replace existing items in 'x'?}

\item{item}{The item to add data to in the list.}

\item{value}{The value to add in the item, it must be a named vector and
element matching is done according to name of items.}

\item{replace.existing}{Do we replace an existing variable?}

\item{mode}{The mode of the seek variable}

\item{default}{The default value to return, in case the variable or the item
does not exist.}
}
\value{
The temporary environment for \code{temp-env()}, the value assigned, added
or changed for \code{assign_temp()}, \code{add_temp()}, \code{change_temp()}, or
\code{get_temp()}. \code{TRUE} or \code{FALSE} for \code{exists_temp()}, \code{delete_temp()} or
\code{rm_temp()}.
}
\description{
Create and manage a temporary environment \code{SciViews:TempEnv}
low enough on the search path so that all loaded packages (except \strong{base})
could easily access objects there.
}
\details{
The temporary environment is attached to the search path for easier
access to its objects.
}
\examples{
ls(temp_env())

# I have a vector v1 with this:
v1 <- c(a = "some v1 text", b = "another v1 text")
# I want to add items whose name is missing in v1 from v2
v2 <- c(a = "v2 text", c = "the missign item")
add_items(v1, v2, replace = FALSE)
# Not the same as
add_items(v1, v2, replace = TRUE)
# This yield different result (names not used and lost!)
add_items(v1, v2, use.names = FALSE)

add_temp("tst", "item1", c(a = 1, b = 2))
# Retrieve this variable
get_temp("tst")
# Add to item1 in this list without replacement
add_temp("tst", "item1", c(a = 45, c = 3), replace = FALSE)
get_temp("tst")
# Same but with replacement of existing items
add_temp("tst", "item1", c(a = 45, c = 3), replace = TRUE)
get_temp("tst")
# Delete the whole variable
delete_temp("tst")

assign_temp("test", 1:10)
# Retrieve this variable
get_temp("test")

change_temp("tst", "item1", 1:10)
# Retrieve this variable
get_temp("tst")
# Create another item in the list
change_temp("tst", "item2", TRUE)
get_temp("tst")
# Change it
change_temp("tst", "item2", FALSE)
get_temp("tst")
# Delete it (= assign NULL to the item)
change_temp("tst", "item2", NULL)
get_temp("tst")
# Delete the whole variable
delete_temp("tst")

assign_temp("test", 1:10)
# Check if this variable exists
exists_temp("test")
# Remove it
delete_temp("test")
# Does it still exists?
exists_temp("test")
}
\seealso{
\code{\link[=assign]{assign()}}, \code{\link[=search]{search()}}, \code{\link[=temp_var]{temp_var()}}
}
\concept{temporary variables}
\keyword{utilities}