tidyselect::where() inconsistencies: where is where()?

Summary: You can do rename(A=1, B=2), can you do the same using rename_with()? my ~str_replace(... paste0()) works, I don't need to change that. But it only works for one variable at a time. Tidyselect suggests wrapping where(~str_replace...) but then complains it can't find it even though I can get where() to work in other instances.

I want to implement rename_with for more than one variable, but I get an error Error: Formula shorthand must be wrapped in where()`.

# Bad
  data %>% select(~str_replace(., "Var_2_", paste0("Issue: Time")))

  # Good
  data %>% select(where(~str_replace(., "Var_2_", paste0("Issue: time"))))

Example original: test%>% rename_with( ~str_replace(., "Var_2_", paste0("Issue: Time")), ~str_replace(., "Var_3_", paste0("Issue: Time")))

when I run test%>% rename_with(where( ~str_replace(., "Var_2_", paste0("Issue: Time")), ~str_replace(., "Var_3_", paste0("Issue: Time"))))

and test%>% rename_with( where(~str_replace(., "Var_2_", paste0("Issue: Time"))), where(~str_replace(., "Var_3_", paste0("Issue: Time"))))

I get Error in where(~str_replace(., "Var_1_", paste0("Gov't surveillance: video wave")), : could not find function "where" And I can't find it tabbing through tidyselect::

But I can run test%>% select(where(is.numeric)) %>% map(sd, na.rm = TRUE) without any issue so it does exist. What am I doing wrong?

Example data:

x <- c("_1_1",

test <- t(as_tibble(rnorm(10, 5.5, .35)))
colnames(test) <- paste0("Var",x)

Read more here: https://stackoverflow.com/questions/66324365/tidyselectwhere-inconsistencies-where-is-where

Content Attribution

This content was originally published by ibm at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: