na.rm argument in unite() is missing

Hello there,

I've been trying to use the na.rm argument in unite() but it doesn't show up as an autocomplete-suggested-argument when typing "na.rm" in RStudio console/script. Furthermore, even if I just manually type and add na.rm = TRUE, the result is that the output doesn't omit the NAs seen in the original data column, but rather pastes them as-is. Thus, I conclude, na.rm argument simply does not work in unite().

This is despite the output for arg(unite) showing:
function (data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE).

I've replicated the problem both on my local machine and on Rstudio Cloud.

Version of tidyr I'm using is 1.0.0

Is this a bug? Or am I missing something very basic?

Thanks,
Emmanuel

Can you provide an example of where it's not working as expected?

I've run the example from tidyr documentation and it works correctly:

library(tidyr)

df <- expand_grid(x = c("a", NA), y = c("b", NA))
df %>% unite("z", x:y, na.rm = TRUE, remove = FALSE)
#> # A tibble: 4 x 3
#>   z     x     y    
#>   <chr> <chr> <chr>
#> 1 a_b   a     b    
#> 2 a     a     <NA> 
#> 3 b     <NA>  b    
#> 4 ""    <NA>  <NA>

Created on 2019-09-16 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.