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

Fix col_labels bug for named label attributes #301

Merged
merged 10 commits into from
Mar 1, 2024
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# teal.data 0.5.0.9001

### Bug fixes
* Fixed bug in `col_labels` causing incorrect label names to be returned when input data contains named label attributes.

# teal.data 0.5.0

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion R/formatters_var_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ col_labels <- function(x, fill = FALSE) {
return(character(0L))
}

labels <- lapply(x, attr, "label")
labels <- lapply(x, function(x) as.vector(attr(x, "label")[[1]]))
pawelru marked this conversation as resolved.
Show resolved Hide resolved

nulls <- vapply(labels, is.null, logical(1L))
if (any(nulls)) {
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-formatters_var_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ testthat::test_that("col_labels returns a vector of column names when fill = TRU
)
})

testthat::test_that("col_labels works with named label attributes", {
x <- iris
attr(x$Species, "label") <- c(Species = "Label for Species")
testthat::expect_true(
"Species" %in% names(col_labels(x))
)
})

pawelru marked this conversation as resolved.
Show resolved Hide resolved

# col_labels ----
testthat::test_that("col_labels<- value accepts character vector", {
Expand Down
Loading