It is not really an error but the message is missleading, the issue is that the number of levels in the variable should be >= 1 be It is actually ok if the variable is of length 0. (and there is no bug if it is a character.)
Should we be more tolerant, should we improve the error message or force the users to use factors ?
library(chevron)
#> Registered S3 method overwritten by 'tern':
#> method from
#> tidy.glm broom
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
proc_data <- syn_data
proc_data$addv <- proc_data$addv[NULL, ]
preprocess(pdt01) <-
function(adam_db, ...) {
adam_db$addv <- adam_db$addv %>%
mutate(across(all_of(c(
"DVSCAT",
"DVTERM"
)), ~ reformat(.x, nocoding))) %>%
mutate(
DVSCAT = with_label(
.data$DVSCAT,
"Category"
),
DVTERM = with_label(
.data$DVTERM,
"Category"
)
) %>%
mutate(DVTERM = stringr::str_wrap(DVTERM, width = 50))
adam_db %>% dunlin::log_filter(.data$DVCAT == "MAJOR", "addv")
}
run(pdt01, proc_data)
#> Error in tryCatch(withCallingHandlers({: 1 assertions failed:
#> * Variable 'adam_db$addv$DVTERM': Must have length >= 1, but has
#> * length 0.
Created on 2024-07-01 with [reprex v2.1.0](https://reprex.tidyverse.org/)
It is not really an error but the message is missleading, the issue is that the number of levels in the variable should be >= 1 be It is actually ok if the variable is of length 0. (and there is no bug if it is a character.)
Should we be more tolerant, should we improve the error message or force the users to use
factors
?