Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

cat: Concatenate and Print

catR Documentation

Concatenate and Print

Description

Outputs the objects, concatenating the representations.catperforms much less conversion thanprint.

Usage

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

Arguments

...

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

file

A connection, or a character string naming the fileto print to. If"" (the default),cat prints to thestandard output connection, the console unless redirected bysink.If it is"|cmd", the output is piped to the command givenby ‘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 isbroken into successive lines. IfFALSE (default), only newlinescreated explicitly by"\n" are printed. Otherwise, theoutput is broken into lines with print width equal to the optionwidth iffill isTRUE, or the value offill if this is numeric. Linefeeds are only insertedbetween elements, strings wider thanfill are notwrapped. Non-positivefill values areignored, with a warning.

labels

character vector of labels for the lines printed.Ignored iffill isFALSE.

append

logical. Only used if the argumentfile is thename of file (and not a connection or"|cmd").IfTRUE output will be appended tofile; otherwise, it will overwrite the contents offile.

Details

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

No linefeeds are output unless explicitly requested by"\n"or if generated by filling (if argumentfill isTRUE ornumeric).

Iffile is a connection and open for writing it is written fromits current position. If it is not open, it is opened for theduration of the call in"wt" mode and then closed again.

Currently only atomic vectors and names are handled,together withNULL and other zero-length objects (which produceno output). Character strings are output ‘as is’ (unlikeprint.default which escapes non-printable characters andbackslash — useencodeString if you want to outputencoded strings usingcat). Other types ofR object should beconverted (e.g., byas.character orformat)before being passed tocat. That includes factors, which areoutput as integer vectors.

cat converts numeric/complex elements in the same way asprint (and not in the same way asas.characterwhich is used by the S equivalent), sooptions"digits" and"scipen" are relevant. However, it usesthe minimum field width necessary for each element, rather than thesame field width for all elements.

Value

None (invisibleNULL).

Note

If any element ofsep contains a newline character, it istreated as a vector of terminators rather than separators, an elementbeing output after every vector elementand a newline after thelast. Entries are recycled as needed.

References

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

See Also

print,format, andpastewhich concatenates into a string.

Examples

iter <- stats::rpois(1, lambda = 10)## print an informative messagecat("iteration = ", iter <- iter + 1, "\n")## 'fill' and label lines:cat(paste(letters, 100* 1:26), fill = TRUE, labels = paste0("{", 1:10, "}:"))

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp