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

Zero-length label worse than null label #740

Open
sda030 opened this issue Nov 15, 2023 · 0 comments
Open

Zero-length label worse than null label #740

sda030 opened this issue Nov 15, 2023 · 0 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@sda030
Copy link

sda030 commented Nov 15, 2023

Came across this in real data (sorry, cannot reproduce the data generation, too complicated). However, this reprex shows that having a variable with a zero-length string causes CHARSXP to fail (understandably).

library(haven)
data <- structure(list(not_working = structure(5:1, format.stata = "%10.0g", label = character(0)), 
                       working = 1:5), row.names = c(NA, -5L), class = c("tbl_df",  "tbl", "data.frame"))
haven::write_dta(data, tempfile(fileext = ".dta")) # Not working, due to not_working
#> Error in write_dta_(data_out, normalizePath(path, mustWork = FALSE), version = stata_file_format(version), : 'Rf_translateCharUTF8' must be called on a CHARSXP, but got 'NULL'
haven::write_dta(data[, "working", drop=FALSE], tempfile(fileext = ".dta")) #Works!

Created on 2023-11-15 with reprex v2.0.2

@gorcha gorcha added the bug an unexpected problem or unintended behavior label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants