paste_xy {powerjoin}R Documentation

Paste helpers

Description

These are similar to paste() but by default ignore NA and empty strings (""). If they are found in a conflicting column we return the value from the other column without using the separator. If both columns have such values we return an empty string.

Usage

paste_xy(x, y, sep = " ", na = NULL, ignore_empty = TRUE)

paste_yx(x, y, sep = " ", na = NULL, ignore_empty = TRUE)

Arguments

x

A vector

y

A vector

sep

separator

na

How to treat NAs, they are ignored by default, if NA the result will be NA, just as with stringr::str_c, if "NA" NAs will be coerced to character just as with paste(). Any other string can be used

ignore_empty

Whether to ignore empty strings, to avoid trailing and leading separators

Value

A character vector

Examples

paste_xy(letters[1:3], c("d", NA, ""))
paste_yx(letters[1:3], c("d", NA, ""))
paste_xy(letters[1:3], c("d", NA, ""), na = NA, ignore_empty = FALSE)
paste_xy(letters[1:3], c("d", NA, ""), na = "NA", ignore_empty = FALSE)

[Package powerjoin version 0.1.0 Index]