-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support dimensions for list environments? #11
Comments
Because list environments formally are environments in R, the internal code prevents us from setting attributes > x <- as.listenv(as.list(1:6))
> x
`listenv` with 6 elements that are not named.
> dim(x) <- c(2,3)
Error in dim(x) <- c(2, 3) : invalid first argument
> attr(x, "dim") <- c(2,3)
Error in attr(x, "dim") <- c(2, 3) : invalid first argument
> attributes(x) <- list(dim=c(2,3))
Error in attributes(x) <- list(dim = c(2, 3)) : invalid first argument So there's some built-in/low-level protection from setting attributes with those names on environments. However, we can set others, e.g. > attr(x, ".dim") <- c(2,3)
> attr(x, ".dim")
[1] 2 3 Also, it turns out we at least can override > dim.listenv <- function(x) attr(x, ".dim")
> `dim<-.listenv` <- function(x, value) { attr(x, ".dim") <- as.integer(value); x }
> dim(x) <- c(3,2)
> dim(x)
[1] 3 2 Similarly for > dimnames.listenv <- function(x) attr(x, ".dimnames")
> `dimnames<-.listenv` <- function(x, value) { attr(x, ".dimnames") <- as.list(value); x }
> dimnames(x) <- list(c("R1", "R2"), c("C1", "C2", "C3"))
> dimnames(x)
[[1]]
[1] "R1" "R2"
[[2]]
[1] "C1" "C2" "C3" Maybe this is enough? Though, not sure that dimensions and their names should be stored as attributes per se or internal objects of the list environment, cf. |
All of the above is now in the develop branch. |
With lists one can do:
Can we add something similar to list environments?
The text was updated successfully, but these errors were encountered: