diff --git a/NEWS.md b/NEWS.md index 8523a9e2..893478b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/haven-stata.R b/R/haven-stata.R index 3ba30632..e3ec854f 100644 --- a/R/haven-stata.R +++ b/R/haven-stata.R @@ -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) } diff --git a/tests/testthat/test-haven-stata.R b/tests/testthat/test-haven-stata.R index f63b80d1..b068a66a 100644 --- a/tests/testthat/test-haven-stata.R +++ b/tests/testthat/test-haven-stata.R @@ -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")) })