Skip to contents

Does the input object have syntactically valid names?

Usage

hasValidNames(x)

hasValidDimnames(x)

Arguments

x

Object.

Value

TRUE on success; FALSE on failure, with cause set.

Note

Updated 2022-05-13.

See also

Examples

## TRUE ====
x <- list("a" = 1L, "b" = 2L)
print(names(x))
#> [1] "a" "b"
print(hasValidNames(x))
#> [1] TRUE

x <- datasets::iris
print(hasValidDimnames(x))
#> [1] TRUE

## FALSE ====
x <- list(
    "1" = 1, # can't start with number
    "foo bar" = 2, # no spaces
    "foo-bar" = 3 # no hyphens
)
print(x)
#> $`1`
#> [1] 1
#> 
#> $`foo bar`
#> [1] 2
#> 
#> $`foo-bar`
#> [1] 3
#> 
print(hasValidNames(x))
#> [1] FALSE

x <- datasets::mtcars
print(hasValidDimnames(x))
#> [1] FALSE