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

read_dta can read labelled doubles but write_dta can't write labelled doubles #343

Closed
cimentadaj opened this issue Jan 29, 2018 · 1 comment
Closed
Labels

Comments

@cimentadaj
Copy link

@cimentadaj cimentadaj commented Jan 29, 2018

library(haven)
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.4.2
#> ── Attaching packages ────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
#> ✔ tibble  1.3.4     ✔ dplyr   0.7.4
#> ✔ tidyr   0.7.2     ✔ stringr 1.2.0
#> ✔ readr   1.1.1     ✔ forcats 0.2.0
#> Warning: package 'tidyr' was built under R version 3.4.2
#> Warning: package 'purrr' was built under R version 3.4.2
#> Warning: package 'dplyr' was built under R version 3.4.2
#> ── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()

stata_dt <- read_dta("http://www.stata-press.com/data/r13/manuf.dta") %>% select(temperature, 
  chemical)

map_chr(stata_dt, typeof)
#> temperature    chemical 
#>    "double"    "double"
map_lgl(stata_dt, is.labelled)
#> temperature    chemical 
#>        TRUE        TRUE

write_dta(stata_dt, tempfile(fileext = ".dta"))
#> Error: Stata only supports labelled integers.
#> Problems: `temperature`, `chemical`

I'm not sure why write_dta is not allowed to save labelled doubles, although up to the previous version it was doing it just fine (at least in my work I've been saving labelled doubles, which were integers but read as doubles by read_dta). I understand that having labelled integers doesn't make sense but most of time labelled doubles are just integers that were read that way. @kuriwaki suggests that write_dta is allowed to save labelled doubles as long as they don't contain decimal points. See #326.

@lock
Copy link

@lock lock bot commented Aug 14, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Aug 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants