strengejacke / sjlabelled

Working with Labelled Data in R

Home Page:https://strengejacke.github.io/sjlabelled

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with tidy-select where() in add-labels()

YannickDiehl opened this issue · comments

The function sjlabelled :: add_labels () does not allow the use of the tidy-select where (). The other tidy-select functions can be used without any problems. Am I missing a mistake of my own here? Would an adjustment be possible?

df <- tibble(
  a1 = sample(0:4, 500, replace = TRUE, prob = c(0.1, 0.2, 0.3, 0.1, 0.4)),
  a2 = sample(0:4, 500, replace = TRUE, prob = c(0.1, 0.5, 0.25, 0.15, 0.1)),
  b1 = sample(0:4, 500, replace = TRUE, prob = c(0.1, 0.25, 0.1, 0.4, 0.25))
)

test1 <- df %>% 
  add_labels(where(~is.numeric(.x)), labels = c("keine Angabe" = 0)) 

test2 <- df %>% 
  add_labels(starts_with("a"), labels = c("keine Angabe" = 0)) 

get_labels(test1$a1)
get_labels(test2$a1)

Thank you and best regards

Yannick