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

Safely getting the column names of a CompressedSplitDFrameList #29

Closed
LTLA opened this issue Dec 1, 2020 · 2 comments · Fixed by #31
Closed

Safely getting the column names of a CompressedSplitDFrameList #29

LTLA opened this issue Dec 1, 2020 · 2 comments · Fixed by #31

Comments

@LTLA
Copy link
Contributor

LTLA commented Dec 1, 2020

Consider:

df <- DataFrame(X=1:26, Y=letters)
out <- split(df, rep(1:4, length.out=nrow(df)))
colnames(out)
## CharacterList of length 4
## [[1]] X Y
## [[2]] X Y
## [[3]] X Y
## [[4]] X Y

I just want a character vector of column names, so I might think of doing colnames(out)[[1]], but this fails for zero-length:

colnames(out[0])[[1]]
## NULL

The only safe way I can think of is:

colnames(unlist(out))
## [1] "X" "Y"

This is already somewhat unintuitive, but becomes a 3-liner if I want to change the column names:

df <- unlist(out)
colnames(df) <- c("x", "y")
out2 <- relist(df, out) # is metadata in 'out' retained in 'out2'?

So it would be nice to have a dedicated getter/setter for CSDFLs - following the columnMetadata example:

columnNames(out)
## [1] "X" "Y"
columnNames(out) <- c("x", "y")
@lawremi
Copy link
Collaborator

lawremi commented Dec 1, 2020

Good point. I get the mcols() vs. columnMetadata() distinction, but colnames() and columnNames() look like synonyms. Perhaps sharedColumnNames() instead? Feel free to submit a PR.

@LTLA
Copy link
Contributor Author

LTLA commented Dec 1, 2020

Poking around in the source code reveals an unexported commonColnames function in DataFrameList-class.R.

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

Successfully merging a pull request may close this issue.

2 participants