View source: R/stabilize_chr.R
| stabilize_chr | R Documentation |
to_chr() checks whether an argument can be coerced to
character without losing information, returning it silently if so.
Otherwise an informative error message is signaled.
stabilize_chr() can check more details about the argument, but is slower
than to_chr().
stabilize_chr_scalar() and to_chr_scalar() are optimized to check for
length-1 character vectors.
stabilize_chr(
x,
...,
allow_null = TRUE,
allow_na = TRUE,
min_size = NULL,
max_size = NULL,
regex = NULL,
x_arg = caller_arg(x),
call = caller_env(),
x_class = object_type(x)
)
stabilize_chr_scalar(
x,
...,
allow_null = TRUE,
allow_zero_length = TRUE,
allow_na = TRUE,
regex = NULL,
x_arg = caller_arg(x),
call = caller_env(),
x_class = object_type(x)
)
to_chr(
x,
...,
x_arg = caller_arg(x),
call = caller_env(),
x_class = object_type(x)
)
## S3 method for class ''NULL''
to_chr(x, ..., allow_null = TRUE, x_arg = caller_arg(x), call = caller_env())
to_chr_scalar(
x,
...,
allow_null = TRUE,
allow_zero_length = TRUE,
x_arg = caller_arg(x),
call = caller_env(),
x_class = object_type(x)
)
x |
The argument to stabilize. |
... |
Arguments passed to methods. |
allow_null |
|
allow_na |
|
min_size |
|
max_size |
|
regex |
|
x_arg |
|
call |
|
x_class |
|
allow_zero_length |
|
These functions have two important differences from
base::as.character():
lists and data.frames are not coerced to character. In base R, such
objects are coerced to character representations of their elements. For
example, as.character(list(1:3)) returns "1:10". In the unlikely event
that this is the expected behavior, use as.character() instead.
NULL values can be rejected as part of the call to this function (with
allow_null = FALSE).
The argument as a character vector.
to_chr("a")
to_chr(letters)
to_chr(1:10)
to_chr(1 + 0i)
to_chr(NULL)
try(to_chr(NULL, allow_null = FALSE))
to_chr_scalar("a")
try(to_chr_scalar(letters))
stabilize_chr(letters)
stabilize_chr(1:10)
stabilize_chr(NULL)
try(stabilize_chr(NULL, allow_null = FALSE))
try(stabilize_chr(c("a", NA), allow_na = FALSE))
try(stabilize_chr(letters, min_size = 50))
try(stabilize_chr(letters, max_size = 20))
try(stabilize_chr(c("hide", "find", "find", "hide"), regex = "hide"))
stabilize_chr_scalar(TRUE)
stabilize_chr_scalar("TRUE")
try(stabilize_chr_scalar(c(TRUE, FALSE, TRUE)))
stabilize_chr_scalar(NULL)
try(stabilize_chr_scalar(NULL, allow_null = FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.