Skip to content

Unable to import SAS files with duplicate column IDs #436

Closed

Description

I've just run into a sas7bdat file with duplicate column names. haven::read_sas() can't import this file because tibble::tibble() doesn't allow duplicate column names, but I don't think haven exposes a way for the user to set .name_repair as requested in the error message.

(Separately, I've looked in tibble for a possible global option for setting the name repair behavior, but I don't think there is one.)

I suspect this issue extends to the other haven::read_* functions as well.

packageVersion("haven")
#> [1] '2.1.0'

ex <- data.frame(
  id1 = letters[1:3],
  id2 = LETTERS[1:3]
)
colnames(ex) <- c("id", "id")
ex
#>   id id
#> 1  a  A
#> 2  b  B
#> 3  c  C

ex_sas7bdat <- fs::path_temp("ex", ext = "sas7bdat")
haven::write_sas(ex, ex_sas7bdat)

haven::read_sas(ex_sas7bdat)
#> Error in df_parse_sas_file(spec_data, spec_cat, encoding = encoding, catalog_encoding = catalog_encoding, : 
#> Evaluation error: Column name `id` must not be duplicated.
#> Use .name_repair to specify repair..

Created on 2019-02-25 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-02-25
#> Packages -----------------------------------------------------------------
#>  package   * version date       source        
#>  base      * 3.5.2   2018-12-22 local         
#>  compiler    3.5.2   2018-12-22 local         
#>  crayon      1.3.4   2017-09-16 CRAN (R 3.5.0)
#>  datasets  * 3.5.2   2018-12-22 local         
#>  devtools    1.13.6  2018-06-27 cran (@1.13.6)
#>  digest      0.6.18  2018-10-10 cran (@0.6.18)
#>  evaluate    0.13    2019-02-12 CRAN (R 3.5.2)
#>  forcats     0.3.0   2018-02-19 CRAN (R 3.5.0)
#>  fs          1.2.6   2018-08-23 CRAN (R 3.5.0)
#>  graphics  * 3.5.2   2018-12-22 local         
#>  grDevices * 3.5.2   2018-12-22 local         
#>  haven       2.1.0   2019-02-19 CRAN (R 3.5.2)
#>  hms         0.4.2   2018-03-10 CRAN (R 3.5.0)
#>  htmltools   0.3.6   2017-04-28 CRAN (R 3.5.0)
#>  knitr       1.20    2018-02-20 CRAN (R 3.5.0)
#>  magrittr    1.5     2014-11-22 CRAN (R 3.5.0)
#>  memoise     1.1.0   2017-04-21 CRAN (R 3.5.0)
#>  methods   * 3.5.2   2018-12-22 local         
#>  pillar      1.3.1   2018-12-15 CRAN (R 3.5.0)
#>  pkgconfig   2.0.2   2018-08-16 cran (@2.0.2) 
#>  R6          2.4.0   2019-02-14 CRAN (R 3.5.2)
#>  Rcpp        1.0.0   2018-11-07 cran (@1.0.0) 
#>  readr       1.3.1   2018-12-21 CRAN (R 3.5.0)
#>  rlang       0.3.1   2019-01-08 CRAN (R 3.5.2)
#>  rmarkdown   1.11    2018-12-08 CRAN (R 3.5.0)
#>  stats     * 3.5.2   2018-12-22 local         
#>  stringi     1.3.1   2019-02-13 CRAN (R 3.5.2)
#>  stringr     1.4.0   2019-02-10 CRAN (R 3.5.2)
#>  tibble      2.0.1   2019-01-12 CRAN (R 3.5.2)
#>  tools       3.5.2   2018-12-22 local         
#>  utils     * 3.5.2   2018-12-22 local         
#>  withr       2.1.2   2018-03-15 CRAN (R 3.5.0)
#>  yaml        2.2.0   2018-07-25 CRAN (R 3.5.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions