[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  paste: Concatenate Strings

##  Description

Concatenate vectors after converting to character.

##  Usage

    
    
    paste (…, sep = " ", collapse = NULL)
    paste0(…, collapse = NULL)

##  Arguments

…

one or more  R  objects, to be converted to character vectors.

sep

a character string to separate the terms. Not ` [ NA_character_
](/link/NA_character_?package=base&version=3.6.2) ` .

collapse

an optional character string to separate the results. Not ` [ NA_character_
](/link/NA_character_?package=base&version=3.6.2) ` .

##  Value

A character vector of the concatenated values. This will be of length zero if
all the objects are, unless ` collapse ` is non-NULL in which case it is a
single empty string.

If any input into an element of the result is in UTF-8 (and none are declared
with encoding ` "bytes" ` , see ` [ Encoding
](/link/Encoding?package=base&version=3.6.2) ` ), that element will be in
UTF-8, otherwise in the current encoding in which case the encoding of the
element is declared if the current locale is either Latin-1 or UTF-8, at least
one of the corresponding inputs (including separators) had a declared encoding
and all inputs were either ASCII or declared.

If an input into an element is declared with encoding ` "bytes" ` , no
translation will be done of any of the elements and the resulting element will
have encoding ` "bytes" ` . If ` collapse ` is non-NULL, this applies also to
the second, collapsing, phase, but some translation may have been done in
pasting object together in the first phase.

##  Details

` paste ` converts its arguments ( _via_ ` [ as.character
](/link/as.character?package=base&version=3.6.2) ` ) to character strings, and
concatenates them (separating them by the string given by ` sep ` ). If the
arguments are vectors, they are concatenated term-by-term to give a character
vector result. Vector arguments are recycled as needed, with zero-length
arguments being recycled to ` "" ` .

Note that ` paste() ` coerces ` [ NA_character_
](/link/NA_character_?package=base&version=3.6.2) ` , the character missing
value, to ` "NA" ` which may seem undesirable, e.g., when pasting two
character vectors, or very desirable, e.g.in ` paste("the value of p is ", p)
` .

` paste0(…, collapse) ` is equivalent to ` paste(…, sep = "", collapse) ` ,
slightly more efficiently.

If a value is specified for ` collapse ` , the values in the result are then
concatenated into a single string, with the elements being separated by the
value of ` collapse ` .

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ toString ](/link/toString?package=base&version=3.6.2) ` typically calls `
paste(*, collapse=", ") ` . String manipulation with ` [ as.character
](/link/as.character?package=base&version=3.6.2) ` , ` [ substr
](/link/substr?package=base&version=3.6.2) ` , ` [ nchar
](/link/nchar?package=base&version=3.6.2) ` , ` [ strsplit
](/link/strsplit?package=base&version=3.6.2) ` ; further, ` [ cat
](/link/cat?package=base&version=3.6.2) ` which concatenates and writes to a
file, and ` [ sprintf ](/link/sprintf?package=base&version=3.6.2) ` for C like
string construction.

‘ [ plotmath ](/link/plotmath?package=base&version=3.6.2) ’ for the use of `
paste ` in plot annotation.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fpaste&utm_source=r-docs&utm_medium=docs&utm_term=paste&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    ## When passing a single vector, paste0 and paste work like as.character.
    paste0(1:12)
    paste(1:12)        # same
    as.character(1:12) # same
    
    ## If you pa