Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (20 sloc) 422 Bytes
#' Replace x
#'
#' @description Replace missing or NA values with a replacement
#' @param x Element to replace
#' @param replacement Defaults to NA_character_
#'
#' @export
#'
#' @examples
#'
#' vec <- c("a", NA, "b")
#' vec %>% purrr::map(replace_x, replacement = "foo")
#'
replace_x <- function(x, replacement = NA_character_) {
if(length(x) == 0 || is.null(x) || is.na(x)) {
replacement
} else {
x
}
}