R/utils.R

Defines functions factor_combine

#' Combine factors
#'
#' @param ... factors to combine
#'
#' @return a factor
#'
#' @noRd
factor_combine <- function(...) {
    f <- rlang::list2(...)
    lvls <- lapply(f, levels)
    lvls <- lapply(seq_along(f), function(i) {
        if (is.null(lvls[[i]])) {
            unique(f[[i]])
        } else {
            lvls[[i]]
        }
    })
    lvls <- Reduce(f = union, x = lvls, init = c())
    factor(unlist(f), levels = lvls)
}

Try the redist package in your browser

Any scripts or data that you put into this service are public.

redist documentation built on Aug. 8, 2025, 7:44 p.m.