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

select_if doesn't work if a column in the tibble is named "i" #4380

Closed
alejandroschuler opened this issue May 22, 2019 · 5 comments
Closed

select_if doesn't work if a column in the tibble is named "i" #4380

alejandroschuler opened this issue May 22, 2019 · 5 comments

Comments

@alejandroschuler
Copy link

@alejandroschuler alejandroschuler commented May 22, 2019

This one took me a few minutes to track down... It appears that if a column in the tibble is named i, select_if will fail. This also applies to mutate_if and possibly others.

packageVersion("dplyr")
[1] ‘0.8.1iris %>% 
rename(i=Sepal.Length) %>% 
select_if(is.numeric)

Error in tibble_vars[[i]] : 
  attempt to select more than one element in vectorIndex
@barryrowlingson
Copy link

@barryrowlingson barryrowlingson commented May 22, 2019

works for me in 0.8.0.1, so I upgraded and now its broken in 0.8.1.

@cderv
Copy link
Contributor

@cderv cderv commented May 23, 2019

This come from the internal dplyr:::tbl_if_vars, here is a reprex.

library(dplyr, warn.conflicts = FALSE)


.tbl <- iris %>% 
  rename(i = Sepal.Length)

.predicate <- dplyr:::as_fun_list(is.numeric, caller_env())
vars <- dplyr:::tbl_if_vars(.tbl, .predicate, caller_env(), .include_group_vars = TRUE)
#> Error in tibble_vars[[i]]: attempt to select more than one element in vectorIndex

Created on 2019-05-23 by the reprex package (v0.3.0.9000)

There is a for if loop with i as iterator variable. I guess tidy eval is mixing things up. I'll dig a bit more ans see what I can find.

@romatik
Copy link
Contributor

@romatik romatik commented May 23, 2019

@cderv, you are right, the error is there. I suggest that this can be fixed like this:

  for (i in seq_len(n)) {
    selected[[i]] <- eval_tidy(quo(.p(.tbl[[tibble_vars[[!!i]]]], ...)), mask)
  }

This corresponds to this line:

for (i in seq_len(n)) {

I can create a PR if this fix is OK.

@cderv
Copy link
Contributor

@cderv cderv commented May 23, 2019

Thanks @romatik for chiming in!
I planned initially to look for a fix tonight - glad to know it has been handled! 😊👍

@lock
Copy link

@lock lock bot commented Nov 23, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Nov 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants