You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running the following script on R 3.6.3 on Windows 10 (64 Bit). tidyverse is 1.3.0, dplyr is 0.8.5, and tidyselect is 1.0.0.
library(tidyverse)
# Sys information
Sys.info()
R.version
packageVersion("dplyr")
packageVersion("tidyselect")
packageVersion("tidyverse")
my_tibble<- tibble(first_var=1:3,
third_var=1:3,
second_var=1:3)
sorted_vars<- c("first_var", "second_var", "third_var", "fourth_var")
# Variable names in original ordermy_tibble %>% names# all_of gives an error because of no "fourth_var"
select(my_tibble, all_of(sorted_vars)) %>%
names# any_of works but does not respect order in "sorted_vars"
select(my_tibble, any_of(sorted_vars)) %>%
names# this works as expected
select(
my_tibble,
all_of(
sorted_vars[sorted_vars%in% names(my_tibble)]
)
) %>% names
At first variables are sorted in the orginal tibble order.
all_of gives an error, of course, because my list of variable names includes a non-existing "fourth_var".
select(my_tibble, all_of(sorted_vars)) %>%
namesError:Can't subset columns that don'texist.xThecolumn`fourth_var`doesn't exist.Run `rlang::last_error()` to see where the error occurred.
all_of based on a variable name list that only includes names for existing variables works as expected. Columns are sorted in the order of the provided list and not in the original order.
any_of works, but I would have expected it to select variables in the order of the list provided. Instead it returns the columns in the same order as in the original tibble.
From the help file ("The order of selected columns is determined by the inputs."), I would also have expected any_of to respect the order of variable names provided. Am I missing out on something here?
The text was updated successfully, but these errors were encountered:
At first variables are sorted in the orginal tibble order.
all_of
gives an error, of course, because my list of variable names includes a non-existing "fourth_var".all_of
based on a variable name list that only includes names for existing variables works as expected. Columns are sorted in the order of the provided list and not in the original order.any_of
works, but I would have expected it to select variables in the order of the list provided. Instead it returns the columns in the same order as in the original tibble.From the help file ("The order of selected columns is determined by the inputs."), I would also have expected
any_of
to respect the order of variable names provided. Am I missing out on something here?The text was updated successfully, but these errors were encountered: