Skip to content

Commit

Permalink
Handle labelled values with no labels (#609)
Browse files Browse the repository at this point in the history
Fixes #606
  • Loading branch information
jmobrien authored Jul 30, 2021
1 parent 102d830 commit 0aabdb4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
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

0 comments on commit 0aabdb4

Please sign in to comment.