[ 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)

#  cat: Concatenate and Print

##  Description

Outputs the objects, concatenating the representations. ` cat ` performs much
less conversion than ` [ print ](/link/print?package=base&version=3.6.2) ` .

##  Usage

    
    
    cat(… , file = "", sep = " ", fill = FALSE, labels = NULL,
        append = FALSE)

##  Arguments

…

R  objects (see ‘Details’ for the types of objects allowed).

file

A [ connection ](/link/connection?package=base&version=3.6.2) , or a character
string naming the file to print to. If ` "" ` (the default), ` cat ` prints to
the standard output connection, the console unless redirected by ` [ sink
](/link/sink?package=base&version=3.6.2) ` . If it is ` "|cmd" ` , the output
is piped to the command given by ` cmd ` , by opening a pipe connection.

sep

a character vector of strings to append after each element.

fill

a logical or (positive) numeric controlling how the output is broken into
successive lines. If ` FALSE ` (default), only newlines created explicitly by
"\n"  are printed. Otherwise, the output is broken into lines with print width
equal to the option ` width ` if ` fill ` is ` TRUE ` , or the value of ` fill
` if this is numeric. Non-positive ` fill ` values are ignored, with a
warning.

labels

character vector of labels for the lines printed. Ignored if ` fill ` is `
FALSE ` .

append

logical. Only used if the argument ` file ` is the name of file (and not a
connection or ` "|cmd" ` ). If ` TRUE ` output will be appended to ` file ` ;
otherwise, it will overwrite the contents of ` file ` .

##  Value

None (invisible ` NULL ` ).

##  Details

` cat ` is useful for producing output in user-defined functions. It converts
its arguments to character vectors, concatenates them to a single character
vector, appends the given ` sep = ` string(s) to each element and then outputs
them.

No linefeeds are output unless explicitly requested by  "\n"  or if generated
by filling (if argument ` fill ` is ` TRUE ` or numeric).

If ` file ` is a connection and open for writing it is written from its
current position. If it is not open, it is opened for the duration of the call
in ` "wt" ` mode and then closed again.

Currently only [ atomic ](/link/atomic?package=base&version=3.6.2) vectors and
[ name ](/link/name?package=base&version=3.6.2) s are handled, together with `
NULL ` and other zero-length objects (which produce no output). Character
strings are output ‘as is’ (unlike ` [ print.default
](/link/print.default?package=base&version=3.6.2) ` which escapes non-
printable characters and backslash --- use ` [ encodeString
](/link/encodeString?package=base&version=3.6.2) ` if you want to output
encoded strings using ` cat ` ). Other types of  R  object should be converted
(e.g., by ` [ as.character ](/link/as.character?package=base&version=3.6.2) `
or ` [ format ](/link/format?package=base&version=3.6.2) ` ) before being
passed to ` cat ` . That includes factors, which are output as integer
vectors.

` cat ` converts numeric/complex elements in the same way as ` print ` (and
not in the same way as ` [ as.character
](/link/as.character?package=base&version=3.6.2) ` which is used by the S
equivalent), so ` [ options ](/link/options?package=base&version=3.6.2) ` `
"digits" ` and ` "scipen" ` are relevant. However, it uses the minimum field
width necessary for each element, rather than the same field width for all
elements.

##  References

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

##  See Also

` [ print ](/link/print?package=base&version=3.6.2) ` , ` [ format
](/link/format?package=base&version=3.6.2) ` , and ` [ paste
](/link/paste?package=base&version=3.6.2) ` which concatenates into a string.

##  Examples

[ Run this