Skip to contents

Acts the same as regular paste, unless na.rm = TRUE, in which case empty strings and NA are removed.

Usage

paste2(..., sep = " ", collapse = NULL, na.rm = TRUE)

Arguments

...

the list of strings to paste

sep

the separator string, " " by default

collapse

the collapse string, NULL by default

na.rm

whether to remove NA and empty strings

Value

string

Details

Due to the contents of vectors passed to this function, elements in vectors may be removed without warning. Sometimes, even the whole vector is omitted. see @examples.

Examples

s1 = c("","a",NA,TRUE)
s2 = c("b","",NA,NULL)
s3 = c(NULL,NA)
paste(s1, s2, s3, sep = ',', collapse = "/")
#> [1] ",b,NA/a,,NA/NA,NA,NA/TRUE,b,NA"
paste(s1, s2, s3, sep = ',', collapse = "/", na.rm = TRUE)
#> [1] ",b,NA,TRUE/a,,NA,TRUE/NA,NA,NA,TRUE/TRUE,b,NA,TRUE"
paste2(s1, s2, s3, sep = ',', collapse = "/")
#> [1] "a,b/TRUE,b"
paste2(s1, s2, s3, sep = ',', collapse = "/", na.rm = TRUE)
#> [1] "a,b/TRUE,b"