Convert an R Object to a Character String or Test for a... (original) (raw)
toString {base} | R Documentation |
---|
Description
is.string(x)
is checking if x
is a “string”, i.e., a[character](../../base/help/character.html)
vector of length(x) == 1
.
toString()
is a helper function for [format](../../base/help/format.html)
to produce a single character string describing an R object.
Usage
is.string(x)
toString(x, ...)
## Default S3 method:
toString(x, width = NULL, collapse=", ", ...)
Arguments
x | the R object to be converted. |
---|---|
width | Suggestion for the maximum field width. Values ofNULL or 0 indicate no maximum. The minimum value accepted is 6 and smaller values are taken as 6. |
collapse | passed to paste(x, *) when concatenating elements. |
... | optional arguments passed to or from methods. |
Details
toString
is a generic function for which methods can be written: only the default method is described here. Most methods should honor thewidth
argument to specify the maximum display width (as measured by [nchar](../../base/help/nchar.html)(type = "width")
) of the result.
The default method first converts x
to character and then concatenates the elements separated by collapse
, by default, ", "
. If width
is supplied and is not NULL
, the default method returns the first width - 4
characters of the result with....
appended, if the full result would use more thanwidth
characters.
Value
is.string()
returns TRUE
or FALSE
.
toString(.)
returns a ‘string’, i.e., a[character](../../base/help/character.html)
vector of length 1.
Author(s)
Robert Gentleman
See Also
[format](../../base/help/format.html)
Examples
x <- c("a", "b", "aaaaaaaaaaa")
toString(x)
toString(x, width = 8)
is.string(x) # FALSE : a character vector of length 3
is.string(x[1]) # TRUE
is.string("") # TRUE
is.string(NA_character_) # TRUE
is.string(character(0)) # FALSE
stopifnot(!is.string(x), !is.string(character()), is.string("abc"), is.string(x[1]))
[Package _base_ version 4.6.0 Index]