Skip to content

Commit

Permalink
error when applying value labels to Date (#157)
Browse files Browse the repository at this point in the history
fix #156
  • Loading branch information
larmarange authored Mar 19, 2024
1 parent 035ad29 commit b3be2c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/val_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ val_labels.data.frame <- function(x, prefixed = FALSE) {
null_action = c("unclass", "labelled"),
value) {
null_action <- match.arg(null_action)
if (null_action == "labelled") {
x <- labelled(x, value, label = val_label(x))
if (!is.null(value) || null_action == "labelled") {
x <- labelled(x, value, label = var_label(x))
}
# otherwise do nothing
x
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-labelled.r
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ test_that(" 'val_label<-' works properly", {
expect_error(val_label(df, 2:3) <- "a")

sub_df <- df[, -match("ch", names(df))]

v <- as.Date("2023-01-01")
l <- as.Date(c("The first day of 2023" = "2023-01-01"))
expect_error(val_labels(v) <- l)
})

test_that(" 'val_label<-.data.frame' works properly", {
Expand Down

0 comments on commit b3be2c4

Please sign in to comment.