Learn R Programming

utile.tools (version 0.2.8)

paste: Concatenate strings

Description

An augmented version of base::paste() with options to manage NA values.

Usage

paste(..., sep = " ", collapse = NULL, na.rm = FALSE)

paste0(..., collapse = NULL, na.rm = FALSE)

Value

Character vector of concatenated values.

Arguments

...

R objects to be converted to character vectors.

sep

A character. A string to separate the terms.

collapse

A character. An string to separate the results.

na.rm

A logical. Whether to remove NA values from 'x'. Note that NA values are also removed from vectors.

Details

The base::paste() function is intentionally designed to coarce NA values to characters that appear in the concatenated character output. This behavior is not always desirable (i.e. when programatically calling paste) and there is currently no means of opting out of this behavior. These augmented functions address this deficit.

See Also

Examples

Run this code
# Base paste() NA handling behavior
paste(
  'The', c('red', NA, 'orange'), 'fox jumped', NA, 'over the fence.',
  collapse = ' '
)

# Removal of NA values
paste(
  'The', c('red', NA, 'orange'), 'fox jumped', NA, 'over the fence.',
  collapse = ' ',
  na.rm = TRUE
)

Run the code above in your browser using DataLab