I am trying to use the tidyselect
function where
with pivot_longer
and am getting the error that the tidyselect
package doesn't support predicates. That was seem somewhat unreasonable, so most likely I have a syntax error. (I realize that SO is not for code debugging.) I think it would help me understand better if someone could show me how to accomplish this task.
d <- dplyr::tribble(
~cups, ~glasses,
"YES", "NO",
"NO" , "YES",
"YES", "NO",
"YES", "NO",
"NO" , "YES",
"YES", "NO",
"NO" , "YES",
"NO" , "YES",
"YES", "NO",
"NO" , "YES",
"YES", "NO",
"NO" , "YES",
"abc", "def"
) %>%
mutate(id = row_number())
This gives the result I want.
the_columns_I_want <- c('cups','glasses')
d %>%
pivot_longer(all_of(the_columns_I_want),values_to = 'result', names_to = 'group')
But I want to select certain types of fields.
d %>%
pivot_longer(where(is.character),values_to = 'result', names_to = 'group')
Show that it does work for dplyr
, So I am not making this mistake: (Tidyverse: This tidyselect interface doesn't support predicates yet)
d %>%
select(where(is.character))