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

fix/improve recode_only() with factors #81

Closed
jmbarbone opened this issue Jan 16, 2022 · 1 comment · Fixed by #106
Closed

fix/improve recode_only() with factors #81

jmbarbone opened this issue Jan 16, 2022 · 1 comment · Fixed by #106
Labels
bug 🐛 Something isn't working easier 🐇 Minimal work enhancement 💎 Feature enhancement
Milestone

Comments

@jmbarbone
Copy link
Owner

library(mark)
x <- factor(c("a", "b", "c"))
recode_only(x, c(new = "new"))
#> [1] 1 2 3
recode_only(x, c(A = "a"))
#> Warning in `[<-.factor`(`*tmp*`, m > 0, value = "A"): invalid factor level, NA
#> generated
#> [1] NA  2  3

Created on 2022-01-16 by the reprex package (v2.0.1)

@jmbarbone jmbarbone added bug 🐛 Something isn't working enhancement 💎 Feature enhancement labels Jan 16, 2022
@jmbarbone jmbarbone added this to the 0.4.3 milestone Jan 16, 2022
@jmbarbone
Copy link
Owner Author

I think this should do it:

recode_only.factor <- function(x, by, vals = NULL) {
  levels(x) <- mark::recode_only(levels(x), by = by, vals = vals)
  x
}

@jmbarbone jmbarbone added the easier 🐇 Minimal work label Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working easier 🐇 Minimal work enhancement 💎 Feature enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant