haven 2.3.0

  tidyverse, haven

  Hadley Wickham

We’re tickled pink to announce the release of haven 2.3.0. haven allows you to read and write SAS, SPSS, and Stata data formats from R, thanks to the wonderful ReadStat C library written by Evan Miller.

You can install haven from CRAN with:

install.packages("haven")

This release is mainly in preparation for dplyr 1.0.0. It includes improved vctrs support for the labelled() class that haven uses to represent labelled vectors that come from SAS, Stata, and SPSS. This is not terribly exciting, but it means that the labelled class is now preserved by every dplyr operation where it makes sense:

library(haven)
library(dplyr, warn.conflicts = FALSE)

x <- labelled(sample(5), c("bad" = 1, "good" = 5), "scores")
df <- tibble(x, y = letters[c(1, 3, 5, 7, 9)])
df
#> # A tibble: 5 x 2
#>           x y    
#>   <int+lbl> <chr>
#> 1  5 [good] a    
#> 2  3        c    
#> 3  4        e    
#> 4  1 [bad]  g    
#> 5  2        i

df %>% arrange(x)
#> # A tibble: 5 x 2
#>           x y    
#>   <int+lbl> <chr>
#> 1  1 [bad]  g    
#> 2  2        i    
#> 3  3        c    
#> 4  4        e    
#> 5  5 [good] a
df %>% filter(y %in% c("a", "c"))
#> # A tibble: 2 x 2
#>           x y    
#>   <int+lbl> <chr>
#> 1  5 [good] a    
#> 2  3        c

bind_rows(df, df)
#> # A tibble: 10 x 2
#>            x y    
#>    <int+lbl> <chr>
#>  1  5 [good] a    
#>  2  3        c    
#>  3  4        e    
#>  4  1 [bad]  g    
#>  5  2        i    
#>  6  5 [good] a    
#>  7  3        c    
#>  8  4        e    
#>  9  1 [bad]  g    
#> 10  2        i

df2 <- tibble(y = letters[1:10])
df2 %>% left_join(df)
#> Joining, by = "y"
#> # A tibble: 10 x 2
#>    y             x
#>    <chr> <int+lbl>
#>  1 a      5 [good]
#>  2 b     NA       
#>  3 c      3       
#>  4 d     NA       
#>  5 e      4       
#>  6 f     NA       
#>  7 g      1 [bad] 
#>  8 h     NA       
#>  9 i      2       
#> 10 j     NA

Acknowledgements

As always thanks to the GitHub community who helped make this release happen: @180312allison, @armenic, @batpigandme, @beckerbenj, @bergen288, @courtiol, @deschen1, @edvbb, @Ghanshyamsavaliya, @hadley, @JackLandry, @Jagadeeshkb, @jimhester, @kurt-vd, @larmarange, @lionel-, @mayer79, @mikmart, @mitchelloharawild, @omsai, @pdbailey0, @randrescastaneda, @richarddmorey, @romainfrancois, @rubenarslan, @sda030, @Sdurier, and @tobwen.

Contents