SwissClinicalTrialOrganisation/secuTrialR

label seems to get "lost" in the secuTrialdata object after subsetting

Closed this issue · 6 comments

Describe the bug
After subsetting a secuTrialdata object the variable labels seems to be dropped

To Reproduce
Read a secuTrial export. Subset it and check the labels.

Expected behavior
Retain variables.

simplest solution would be to reapply labels shortly before returning the object...

Sounds good. I'll ask our new colleague in Basel to do it once she's a little more settled. Probably a good task to get going.

R in general doesn't keep any custom attributes when subsetting. So maybe we need a custom [ method for secuTrialdata objects, or we could use an external package like "sticky" to make all attributes persistent: https://cran.r-project.org/web/packages/sticky/vignettes/introduction.html

Quick workaround for the tidyverse suggested by @suvi-subra: Subsetting with dplyr's filter() preserves all labels.

if you have time, please feel free to make a PR 😉

@aghaynes I am playing around, but I couldn't find a solution yet. And the workaround doesn't solve the OP, labels should be preserved regardless of the method used to subset.