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

*_if operates on all columns if a predicate returns just character() (= no match) #1989

Closed
luke-a opened this issue Jul 4, 2016 · 2 comments
Closed

Comments

@luke-a
Copy link

@luke-a luke-a commented Jul 4, 2016

I don't know if this is an intended behavior (confused me):

library(dplyr)
df <- data_frame( x = as.factor("a"), y = 1L )
str(df)
 # $ x: Factor w/ 1 level "a": 1
 # $ y: int 1

dplyr:::probe_colwise_names(df, is.character)
# character(0)

df <- mutate_if(df, is.character, as.factor)
str(df)
# Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1 obs. of  2 variables:
#  $ x: Factor w/ 1 level "a": 1
#  $ y: Factor w/ 1 level "1": 1 #

mutate_if turned the integer column y into a factor on an is.character check.

My packageVersion("dplyr") is ‘0.5.0.9000’

@luke-a luke-a changed the title *_if() operates on all columns if a predicate returns just character() (= no match) *_if operates on all columns if a predicate returns just character() (= no match) Jul 4, 2016
lionel- added a commit to lionel-/dplyr that referenced this issue Jul 11, 2016
lionel- added a commit to lionel-/dplyr that referenced this issue Jul 11, 2016
@hadley hadley closed this in #2011 Aug 24, 2016
@karimn
Copy link

@karimn karimn commented Mar 3, 2017

Is this fix not in dplyr v0.5.0? I'm seeing this:

> data.frame(x = 1:10, y = 1:10) %>% dplyr::mutate_if(is.factor, funs(fct_relevel(., "10"))) 
Error in mutate_impl(.data, dots) : 
  `f` must be a factor (or character vector).

Loading

@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Mar 4, 2017

@karimn
It seems that v0.5.0 does not contain the fix (as it was committed in Aug 2016, whereas v0.5.0 was released in June 2016). You need to install_github("hadley/dplyr") for now.

Loading

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
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.

None yet
3 participants