Is var_labels fully tidyverse and NSE compatible?
marianschmidt opened this issue · comments
Hi Daniel,
I am using the sjlabelled package in a tidyverse environment. I am still dreaming of being able to use your package in a way that I can easily define labels in a separate dataframe and then write a function to apply these labels to my real dataset. On the way there I tried your new var_labels function which you flagged to use in a pipe-workflow. I have then tried the following simple procedure borrowed from the last paragraph in this dplyr vignette https://dplyr.tidyverse.org/articles/programming.html#quasiquotation that reads "Setting variable names". Do you think the following code should work with your package?
testdf <- data.frame(PSEUDOPATID = 1:5, x = "zero", y=2)
varname <- "PSEUDOPATID"
varlabel <- "Patient ID"
#first test - trying to assign labels from the two values
labelled_test <- testdf %>%
var_labels(!!varname := varlabel)
#second test - trying to assign labels RHS only
labelled_test <- testdf %>%
var_labels(PSEUDOPATID = varlabel)
#third test - trying to assign labels LHS only
labelled_test <- testdf %>%
var_labels(!!varname := "Patient ID LHS unquote only")
#works manually
labelled_test <- testdf %>%
var_labels(PSEUDOPATID = "Patient ID manual")
I am not 100% sure if all my examples are correct, but I would assume that if possible with your function, at least the third test example would work.
That's a good point. Currently, none of the above examples (except the last one) work with var_labels()
. Maybe I should think about implementing tidy eval into the package, and see for which functions this makes sense.
True "tidy eval" is the correct term. I would be great if you could look into this. For me personally, setting variable and value labels would be the most valuable use.