Skip to content
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

IDEA: Add dfenv()? #10

Open
HenrikBengtsson opened this issue Oct 8, 2015 · 3 comments
Open

IDEA: Add dfenv()? #10

HenrikBengtsson opened this issue Oct 8, 2015 · 3 comments

Comments

@HenrikBengtsson
Copy link
Collaborator

HenrikBengtsson commented Oct 8, 2015

Would it make sense to also have a data frame environment that is an environment but emulates how a data frame works? For example,

df <- dfenv(a=1:3, b=c("x", "y", "z"))
df <- cbind(df, c=c(TRUE, FALSE, TRUE))
df$d <- 5:7
@HenrikBengtsson
Copy link
Collaborator Author

HenrikBengtsson commented Oct 8, 2015

@HenrikBengtsson
Copy link
Collaborator Author

HenrikBengtsson commented Dec 28, 2015

This should now be much easier given that dimensions are supported together with subsetting along dimensions.

Here's the basic framework:

> df <- listenv()
> dim(df) <- c(10,2)
> colnames(df) <- c("a", "b")
> df[,"a"] <- 1:10
> df[,"b"] <- letters[1:10]
> A 'listenv' matrix with 20 unnamed elements arranged in 10x2 unnamed rows and columns ('a', 'b').
> unlist(df[,"a"])
 [1]  1  2  3  4  5  6  7  8  9 10
> unlist(df[,"b"])
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"

For a dfenv class inheriting from listenv, operators $ and $<- needs to be overridden. The should call corresponding single-column subsetting methods. The latter should in turn coerce such that the elements belonging to the same column should all have the same data type. The constructor dfenv() should emulate data.frame() in how it validates and interprets the arguments.

@HenrikBengtsson
Copy link
Collaborator Author

In the same vein, one could imagine a tibbleenv that emulates tibble objects while being environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant