R/util_paste_with_na.R

Defines functions util_paste0_with_na util_paste_with_na

#' Paste strings but keep NA
#'
#' @param ... other arguments passed to `paste`
#'
#' @return [character] pasted strings
#'
#' @noRd
util_paste_with_na <- function(...) {
  res <- paste(...)
  res[as.logical(rowSums(do.call(data.frame, lapply(list(...), is.na))))] <-
    NA_character_
  res
}

#' Paste strings but keep NA (`paste0`)
#'
#' @param ... other arguments passed to `paste0`
#'
#' @return [character] pasted strings
#'
#' @noRd
util_paste0_with_na <- function(...) {
  res <- paste0(...)
  res[as.logical(rowSums(do.call(data.frame, lapply(list(...), is.na))))] <-
    NA_character_
  res
}

Try the dataquieR package in your browser

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

dataquieR documentation built on Jan. 8, 2026, 5:08 p.m.