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

mutate_if() w/ single column breaks in r-devel #2114

Closed
wibeasley opened this issue Sep 8, 2016 · 5 comments
Closed

mutate_if() w/ single column breaks in r-devel #2114

wibeasley opened this issue Sep 8, 2016 · 5 comments
Assignees
Labels
bug an unexpected problem or unintended behavior

Comments

@wibeasley
Copy link
Contributor

In the recent r-devel, mutate_if() isn't working under some conditions when the dataset has only one column.

ds_1a <- data.frame(
  id               = 1L:5L,
  stringsAsFactors = FALSE
)

ds_1b <- dplyr::mutate_if(
  ds_1a,
  is.character,
  function(x) dplyr::coalesce(x, "-") #Replace NAs with blanks
)

The error is

Error in evalq(sys.calls(), <environment>) : 
  Vector 1 has type 'character' not 'integer'

But everything is fine with a second column:

ds_2a <- data.frame(
  id               = 1L:5L,
  name             = c("a", "b", NA_character_, "c", "d"),
  stringsAsFactors = FALSE
)
ds_2b <- dplyr::mutate_if(
  ds_2a,
  is.character,
  function(x) dplyr::coalesce(x, "-") #Replace NAs with blanks
)

output:

> ds_2b
  id name
1  1    a
2  2    b
3  3    -
4  4    c
5  5    d

I think the problem is with the predicate. That error is identical to if coalesce is called directly (when the two arguments have different data types):

> dplyr::coalesce(1L:5L, "")
Error: Vector 1 has type 'character' not 'integer'

The problem is avoided on Linux & Windows with 3.3.1. But it's occurring Travis and a local Windows machine:

> sessionInfo()
R Under development (unstable) (2016-09-06 r71220)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] REDCapR_0.9.5.9004

loaded via a namespace (and not attached):
 [1] httr_1.2.1     lazyeval_0.2.0 magrittr_1.5   assertthat_0.1
 [5] R6_2.1.3       DBI_0.5        tools_3.4.0    dplyr_0.5.0   
 [9] tibble_1.2     curl_1.2       Rcpp_0.12.7  
@lionel-
Copy link
Member

lionel- commented Sep 15, 2016

I cannot reproduce on R-devel, osx. That looks like a bug in R. What do you get when you run

tbl_vars(df)

and

vapply(df, is.character, logical(1))

@wibeasley
Copy link
Contributor Author

wibeasley commented Sep 21, 2016

> tbl_vars(ds_1a)
[1] "id"

> vapply(ds_1a, is.character, logical(1))
   id 
FALSE 
> tbl_vars(ds_2a)
[1] "id"   "name"

> vapply(ds_2a, is.character, logical(1))
   id  name 
FALSE  TRUE 

I cannot reproduce on R-devel, osx. That looks like a bug in R.

This may be way off, but I'll swing away anyway. If it's not showing up on R-devel osx, could it be related to the new toolchain? I used the top link above. Maybe the Windows and Travis builds are using the new gcc toolchain, while th osx is not? I see that Travis build is using gcc 4.6.3.

Tell me if there's a different build of R you'd like me to try.

image

EDIT: I get the same error with yesterday's version of R-devel:

> sessionInfo()
R Under development (unstable) (2016-09-20 r71321)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] dplyr_0.5.0

loaded via a namespace (and not attached):
[1] lazyeval_0.2.0 magrittr_1.5   R6_2.1.3       assertthat_0.1
[5] DBI_0.5-1      tools_3.4.0    tibble_1.2     Rcpp_0.12.7

@krlmlr
Copy link
Member

krlmlr commented Nov 7, 2016

Are you still seeing these problems?

@wibeasley
Copy link
Contributor Author

Sorry, it took a while to get back to a machine I could put r-dev on.

Yes, the error is still the same error.

Error in evalq(sys.calls(), <environment>) : 
  Vector 1 has type 'character' not 'integer'
> sessionInfo()
R Under development (unstable) (2016-11-29 r71698)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.4.0 lazyeval_0.2.0 magrittr_1.5   R6_2.2.0       assertthat_0.1 DBI_0.5-1      tools_3.4.0    dplyr_0.5.0    tibble_1.2     Rcpp_0.12.8   

@hadley hadley added bug an unexpected problem or unintended behavior data frame labels Feb 2, 2017
@hadley hadley added nse and removed data frame labels Feb 20, 2017
@hadley
Copy link
Member

hadley commented Feb 22, 2017

Given that we can't reproduce, I'm going to close. For future reference, I've included a simpler reprex below.

library(dplyr, warn.conflicts = FALSE)

df <- tibble(id = 1:5)
dplyr::mutate_if(df, is.character, coalesce, "-")
#> # A tibble: 5 × 1
#>      id
#>   <int>
#> 1     1
#> 2     2
#> 3     3
#> 4     4
#> 5     5

@hadley hadley closed this as completed Feb 22, 2017
wibeasley added a commit to wibeasley/dplyr that referenced this issue Feb 22, 2017
@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
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants