Learn R Programming

assertive (version 0.1-7)

assert_all_are_valid_variable_names: Is the string a valid variable name?

Description

Checks strings to see if they are valid variable names.

Usage

assert_all_are_valid_variable_names(x,
    allow_reserved = TRUE, allow_duplicates = TRUE)

  assert_any_are_valid_variable_names(x,
    allow_reserved = TRUE, allow_duplicates = TRUE)

  is_valid_variable_name(x, allow_reserved = TRUE,
    allow_duplicates = TRUE)

Arguments

x
Input to check.
allow_reserved
If TRUE then "..." and "..1", "..2", etc. are considered valid.
allow_duplicates
If TRUE then duplicated names are allowed.

Value

  • TRUE if the input is a valid variable name. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

References

http://4dpiecharts.com/2011/07/04/testing-for-valid-variable-names/

See Also

make.names.

Examples

Run this code
assert_all_are_valid_variable_names(c("x", "y_y0.y", ".", "...", "..1"))
#These examples should fail.
assert_all_are_valid_variable_names(c("...", "..1"), allow_reserved = FALSE)
assert_all_are_valid_variable_names(c("x", "x"), allow_duplicates = FALSE)

Run the code above in your browser using DataLab