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

Fixing write_dta labels checking, addressing #606 #609

Merged
merged 4 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# haven (development version)

* `write_dta()` now correctly handles "labelled"-class numeric (double) variables
that don't have value labels (@jmobrien, #606, #609).

* `write_dta()` now allows variable names up to 32 characters (@sbae, #605).

* Fix issue with `read_dta()` crashing R when StrL variables with missing values
Expand Down
4 changes: 4 additions & 0 deletions R/haven-stata.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ validate_dta_label <- function(label) {
# helpers -----------------------------------------------------------------

has_non_integer_labels <- function(x) {
if (is.null(attr(x, "labels"))) {
return(FALSE)
}

if (!is.labelled(x)) {
return(FALSE)
}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-haven-stata.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ test_that("can write labelled with NULL labels", {
chr <- labelled(c("a", "b"), NULL)

expect_equal(roundtrip_var(int, "dta"), c(1L, 2L))
expect_equal(roundtrip_var(num, "dta"), c(1L, 2L))
expect_equal(roundtrip_var(chr, "dta"), c("a", "b"))
})

Expand Down