Version: | 0.9.1 |
Depends: | R (≥ 3.1.2) |
Suggests: | R.utils, R.rsp, markdown |
VignetteBuilder: | R.rsp |
Title: | Environments Behaving (Almost) as Lists |
Description: | List environments are environments that have list-like properties. For instance, the elements of a list environment are ordered and can be accessed and iterated over using index subsetting, e.g. 'x <- listenv(a = 1, b = 2); for (i in seq_along(x)) x[[i]] <- x[[i]] ^ 2; y <- as.list(x)'. |
License: | LGPL-2.1 | LGPL-3 [expanded from: LGPL (≥ 2.1)] |
LazyLoad: | TRUE |
URL: | https://listenv.futureverse.org, https://github.com/HenrikBengtsson/listenv |
BugReports: | https://github.com/HenrikBengtsson/listenv/issues |
RoxygenNote: | 7.3.1 |
NeedsCompilation: | no |
Packaged: | 2024-01-28 20:40:45 UTC; henrik |
Author: | Henrik Bengtsson [aut, cre, cph] |
Maintainer: | Henrik Bengtsson <henrikb@braju.com> |
Repository: | CRAN |
Date/Publication: | 2024-01-29 13:10:06 UTC |
Get elements of list environment
Description
Get elements of list environment
Usage
## S3 method for class 'listenv'
x$name
Arguments
x |
A list environment. |
name |
The name or index of the element to retrieve. |
Value
The value of an element or NULL
if the element does not exist.
Set an element of list environment
Description
Set an element of list environment
Usage
## S3 replacement method for class 'listenv'
x$name <- value
Arguments
x |
A list environment. |
name |
Name or index of element |
value |
The value to assign to the element |
Transpose a 'listenv' array by permuting its dimensions
Description
Transpose a 'listenv' array by permuting its dimensions
Usage
## S3 method for class 'listenv'
aperm(a, perm, ...)
## S3 method for class 'listenv'
t(x)
Arguments
a , x |
(listenv) The list environment to be transposed |
perm |
(integer vector) An index vector of length |
... |
Additional arguments passed to |
Value
Returns a list environment with permuted dimensions
See Also
These functions works like base::aperm()
and base::t()
.
Examples
x <- as.listenv(1:6)
dim(x) <- c(2, 3)
dimnames(x) <- list(letters[1:2], LETTERS[1:3])
print(x)
x <- t(x)
print(x)
x <- aperm(x, perm = 2:1)
print(x)
List representation of a list environment
Description
List representation of a list environment
Usage
## S3 method for class 'listenv'
as.list(x, all.names = TRUE, sorted = FALSE, ...)
Arguments
x |
A list environment. |
all.names |
If |
sorted |
If |
... |
Not used. |
Value
A list.
Set the dimension of an object
Description
Set the dimension of an object
Usage
dim_na(x) <- value
Arguments
x |
An R object, e.g. a list environment, a matrix, an array, or a data frame. |
value |
A numeric vector coerced to integers.
If one of the elements is missing, then its value is inferred from the
other elements (which must be non-missing) and the length of |
Value
An object with the dimensions set, similar to what
dim(x) <- value
returns.
Examples
x <- 1:6
dim_na(x) <- c(2, NA)
print(dim(x)) ## [1] 2 3
Get name of variable for a specific element of list environment
Description
Get name of variable for a specific element of list environment
Usage
get_variable(...)
## S3 method for class 'listenv'
get_variable(x, name, mustExist = FALSE, create = !mustExist, ...)
Arguments
x |
A list environment. |
name |
The name or index of element of interest. |
mustExist |
If |
create |
If |
Value
The name of the underlying variable
Number of elements in list environment
Description
Number of elements in list environment
Usage
## S3 method for class 'listenv'
length(x)
Arguments
x |
A list environment. |
Create a list environment
Description
Create a list environment
Usage
listenv(...)
as.listenv(...)
Arguments
... |
(optional) Named and/or unnamed objects to be assigned to the list environment. |
Value
An environment of class listenv
.
Examples
x <- listenv(c = 2, a = 3, d = "hello")
print(names(x))
names(x)[2] <- "A"
x$b <- 5:8
y <- as.list(x)
str(y)
z <- as.listenv(y)
Name map for elements of list environment
Description
Name map for elements of list environment
Usage
mapping(x, ...)
map(x, ...)
Arguments
x |
A list environment. |
Value
A named character vector
Names of elements in list environment
Description
Names of elements in list environment
Usage
## S3 method for class 'listenv'
names(x)
Arguments
x |
A list environment. |
Helper function to infer target from expression and environment
Description
Helper function to infer target from expression and environment
Usage
parse_env_subset(
expr,
envir = parent.frame(),
substitute = TRUE,
is_variable = TRUE
)
Arguments
expr |
An expression. |
envir |
An environment. |
substitute |
If |
is_variable |
(logical) If TRUE and an element name is specified, then the name is checked to be a valid variable name. |
Value
A named list with elements:
envir
An environment (defaults to argument
envir
)name
A character vector. ...
op
...
subset
A list of
NULL
. ...idx
An integer vector or
NULL
. ...exists
A logical vector of length
length(idx)
withTRUE
andFALSE
values.code
The deparsed expression
expr
coerced to a single character string.
Removes the dimension of an object
Description
Removes the dimension of an object
Usage
undim(x, ...)
Arguments
x |
An object with or without dimensions |
... |
Not used. |
Details
This function does attr(x, "dim") <- NULL
, which automatically also does
attr(x, "dimnames") <- NULL
.
However, other attributes such as names attributes are preserved,
which is not the case if one do dim(x) <- NULL
.
Value
The object with the dimension attribute removed.