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

write_xpt ignores top level label attribute (but read_xpt honors it) #562

Closed
bergsmat opened this issue Jan 8, 2021 · 2 comments
Closed
Labels
reprex needs a minimal reproducible example

Comments

@bergsmat
Copy link

bergsmat commented Jan 8, 2021

The specification for SAS Transport (https://support.sas.com/techsup/technote/ts140.pdf) provides that each dataset may have a label, not to be confused with column labels. haven::read_xpt() honors these where they exist, but write_xpt() does not (at least, does not react to attribute 'label' and apparently does not support alternative mechanism of supplying same). 'label' is not to be confused with 'name' which is supported (but cannot contain spaces ... consider adding that to documentation). I have not tried CRAN version 2.3.1 but there are no changes in documentation. I'd like to see data.frame 'label' written by write_xpt() to wherever read_xpt() is retrieving it.

library(SASxport) # 1.6.0
library(haven)    # 2.1.0
library(magrittr)
label(mtcars) <- 'My Cars'
mtcars %>% write.xport(file = 'SASxp.xpt') 
mtcars %>% write_xpt('haven.xpt') 
'SASxp.xpt' %>% read.xport %>% attributes %$% label # "My Cars"
'haven.xpt' %>% read.xport                          # no SAS header! (different problem)
'SASxp.xpt' %>% read_xpt   %>% attributes %$% label # "My Cars"
'haven.xpt' %>% read_xpt   %>% attributes %>% names # no label 

@hadley
Copy link
Member

hadley commented Apr 8, 2021

Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session.

@hadley hadley added the reprex needs a minimal reproducible example label Apr 8, 2021
@bergsmat
Copy link
Author

library(SASxport)
library(haven)
library(magrittr)
label(mtcars) <- 'My Cars'
mtcars %>% write.xport(file = 'SASxp.xpt') 
mtcars %>% write_xpt('haven.xpt') 
'SASxp.xpt' %>% read.xport %>% attributes %$% label # "My Cars"
#> [1] "My Cars"
'haven.xpt' %>% read.xport                          # no SAS header! (different problem)
#> Error in read.xport(.): The specified file does not start with a SAS xport file header!
'SASxp.xpt' %>% read_xpt   %>% attributes %$% label # "My Cars"
#> [1] "My Cars"
'haven.xpt' %>% read_xpt   %>% attributes %>% names # no label 
#> [1] "names"     "row.names" "class"

Created on 2021-04-26 by the reprex package (v2.0.0)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2021-03-01 r80047)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       America/Indianapolis                              
#>  date     2021-04-26                                        
#> 
#> - Packages -------------------------------------------------------------------
#>  package      * version date       lib source        
#>  assertthat     0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
#>  backports      1.2.1   2020-12-09 [1] CRAN (R 4.1.0)
#>  base64enc      0.1-3   2015-07-28 [1] CRAN (R 4.1.0)
#>  checkmate      2.0.0   2020-02-06 [1] CRAN (R 4.1.0)
#>  cli            2.3.1   2021-02-23 [1] CRAN (R 4.1.0)
#>  cluster        2.1.1   2021-02-14 [2] CRAN (R 4.1.0)
#>  colorspace     2.0-0   2020-11-11 [1] CRAN (R 4.1.0)
#>  crayon         1.4.1   2021-02-08 [1] CRAN (R 4.1.0)
#>  data.table     1.14.0  2021-02-21 [1] CRAN (R 4.1.0)
#>  digest         0.6.27  2020-10-24 [1] CRAN (R 4.1.0)
#>  dplyr          1.0.4   2021-02-02 [1] CRAN (R 4.1.0)
#>  ellipsis       0.3.1   2020-05-15 [1] CRAN (R 4.1.0)
#>  evaluate       0.14    2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi          0.4.2   2021-01-15 [1] CRAN (R 4.1.0)
#>  forcats        0.5.1   2021-01-27 [1] CRAN (R 4.1.0)
#>  foreign        0.8-81  2020-12-22 [2] CRAN (R 4.1.0)
#>  Formula        1.2-4   2020-10-16 [1] CRAN (R 4.1.0)
#>  fs             1.5.0   2020-07-31 [1] CRAN (R 4.1.0)
#>  generics       0.1.0   2020-10-31 [1] CRAN (R 4.1.0)
#>  ggplot2        3.3.3   2020-12-30 [1] CRAN (R 4.1.0)
#>  glue           1.4.2   2020-08-27 [1] CRAN (R 4.1.0)
#>  gridExtra      2.3     2017-09-09 [1] CRAN (R 4.1.0)
#>  gtable         0.3.0   2019-03-25 [1] CRAN (R 4.1.0)
#>  haven        * 2.3.1   2020-06-01 [1] CRAN (R 4.1.0)
#>  highr          0.8     2019-03-20 [1] CRAN (R 4.1.0)
#>  Hmisc          4.5-0   2021-02-28 [1] CRAN (R 4.1.0)
#>  hms            1.0.0   2021-01-13 [1] CRAN (R 4.1.0)
#>  htmlTable      2.1.0   2020-09-16 [1] CRAN (R 4.1.0)
#>  htmltools      0.5.1.1 2021-01-22 [1] CRAN (R 4.1.0)
#>  htmlwidgets    1.5.3   2020-12-10 [1] CRAN (R 4.1.0)
#>  jpeg           0.1-8.1 2019-10-24 [1] CRAN (R 4.1.0)
#>  knitr          1.31    2021-01-27 [1] CRAN (R 4.1.0)
#>  lattice        0.20-41 2020-04-02 [2] CRAN (R 4.1.0)
#>  latticeExtra   0.6-29  2019-12-19 [1] CRAN (R 4.1.0)
#>  lifecycle      1.0.0   2021-02-15 [1] CRAN (R 4.1.0)
#>  magrittr     * 2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
#>  Matrix         1.3-2   2021-01-06 [2] CRAN (R 4.1.0)
#>  munsell        0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
#>  nnet           7.3-15  2021-01-24 [2] CRAN (R 4.1.0)
#>  pillar         1.5.0   2021-02-22 [1] CRAN (R 4.1.0)
#>  pkgconfig      2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  png            0.1-7   2013-12-03 [1] CRAN (R 4.1.0)
#>  ps             1.5.0   2020-12-05 [1] CRAN (R 4.1.0)
#>  purrr          0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  R6             2.5.0   2020-10-28 [1] CRAN (R 4.1.0)
#>  RColorBrewer   1.1-2   2014-12-07 [1] CRAN (R 4.1.0)
#>  Rcpp           1.0.6   2021-01-15 [1] CRAN (R 4.1.0)
#>  readr          1.4.0   2020-10-05 [1] CRAN (R 4.1.0)
#>  reprex         2.0.0   2021-04-02 [1] CRAN (R 4.1.0)
#>  rlang          0.4.10  2020-12-30 [1] CRAN (R 4.1.0)
#>  rmarkdown      2.7     2021-02-19 [1] CRAN (R 4.1.0)
#>  rpart          4.1-15  2019-04-12 [2] CRAN (R 4.1.0)
#>  rstudioapi     0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  SASxport     * 1.7.0   2020-03-10 [1] CRAN (R 4.1.0)
#>  scales         1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
#>  sessioninfo    1.1.1   2018-11-05 [1] CRAN (R 4.1.0)
#>  stringi        1.5.3   2020-09-09 [1] CRAN (R 4.1.0)
#>  stringr        1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  survival       3.2-7   2020-09-28 [2] CRAN (R 4.1.0)
#>  tibble         3.1.0   2021-02-25 [1] CRAN (R 4.1.0)
#>  tidyselect     1.1.0   2020-05-11 [1] CRAN (R 4.1.0)
#>  utf8           1.1.4   2018-05-24 [1] CRAN (R 4.1.0)
#>  vctrs          0.3.6   2020-12-17 [1] CRAN (R 4.1.0)
#>  withr          2.4.1   2021-01-26 [1] CRAN (R 4.1.0)
#>  xfun           0.21    2021-02-10 [1] CRAN (R 4.1.0)
#>  yaml           2.2.1   2020-02-01 [1] CRAN (R 4.1.0)
#> 
#> [1] C:/Users/tim.bergsma/Documents/R/win-library/4.1
#> [2] C:/Program Files/R/R-devel/library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants