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

Adding labels when column order doesn't match spec #158

Open
michaelmcd18 opened this issue Aug 16, 2024 · 0 comments
Open

Adding labels when column order doesn't match spec #158

michaelmcd18 opened this issue Aug 16, 2024 · 0 comments

Comments

@michaelmcd18
Copy link

I'm looking to apply labels from a spec file to variables during data assembly. Ideally I could do this to intermediate data.frames, where only a subset of the variables are derived. An example case is below:

spec <- yspec::ys_help$spec()

df <- data.frame(CMT = c(1, 2, 3, 1), ID = c(1, 2, 3, 4), SUBJ = c("A1", "A2", "B1", "C1"))

In this case, I've just derived CMT, ID and SUBJ. Ideally I'd like to apply their labels from the spec to provide context for the QCer or future authors.

If I run yspec::ys_add_labels(df, spec) I get an error saying the names of the data aren't identical to the spec, which makes sense. But if I try this workaround yspec::ys_add_labels(df, spec[names(spec) %in% names(df)]) I also get an error. This is due to the columns in my data not matching the order of the columns in the spec, so the identical check fails.

I do get it to work if I set the data columns to match the order the columns appear in the spec
yspec::ys_add_labels(df %>% select(ID, SUBJ, CMT), spec[names(spec) %in% names(df)])

Would it be possible to change the identical requirement in yspec::ys_add_labels to something that checks that all names in spec are in the data provided?

Also not sure if this would cause issues elsewhere, but if I could give the full spec and it only apply labels to matching columns in the data and spec that would be most ideal

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

No branches or pull requests

1 participant