You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
The text was updated successfully, but these errors were encountered:
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:
In this case, I've just derived
CMT
,ID
andSUBJ
. 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 workaroundyspec::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
The text was updated successfully, but these errors were encountered: