Package 'listenv'

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)'.
Authors: Henrik Bengtsson [aut, cre, cph]
Maintainer: Henrik Bengtsson <[email protected]>
License: LGPL (>= 2.1)
Version: 0.9.1
Built: 2024-12-19 06:52:38 UTC
Source: CRAN

Help Index


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 dim(a)

...

Additional arguments passed to base::aperm().

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)

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 x.

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

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)