This code used to work, as of about May 1 2017 (dplyr
version 0.5.0). With dplyr
version 0.7 it fails with Error: Variable context not set
. I couldn't find the solution googling around or looking in the dplyr NEWS file.
This part is fine (setting up the example - could probably be simplified ...)
xx <- data.frame(stud_number=1:3,HW1=rep(0,3),HW2=c(NA,1,1),junk=rep(NA,3))
repl_1_NA <- function(x) { return(replace(x,which(x==1),NA)) }
hw1 <- xx %>% select(c(stud_number,starts_with("HW")))
Now try to use mutate_at()
: fails with dplyr
version >= 0.7.0
hw1 %>% mutate_at(starts_with("HW"),repl_1_NA)
When using starts_with()
as the column selector for mutate_at
, we now need to wrap it in vars()
, so the final code line should read
hw1 %>% mutate_at(vars(starts_with("HW")),repl_1_NA)
I figured this out by looking at the solution to this question and thought I would post it here as a signpost for others ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With