Does the input object have syntactically valid names?

hasValidNames(x, .xname = getNameInParent(x))

hasValidDimnames(x, .xname = getNameInParent(x))

Arguments

x

Object.

.xname

Not intended to be used directly.

Value

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

See also

Examples

## TRUE ==== x <- list(a = 1, b = 2) names(x)
#> [1] "a" "b"
hasValidNames(x)
#> [1] TRUE
x <- datasets::iris lapply(dimnames(x), head)
#> [[1]] #> [1] "1" "2" "3" "4" "5" "6" #> #> [[2]] #> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" #>
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 #>
hasValidNames(x)
#> [1] FALSE #> Cause of failure: #> x does not have valid names.
x <- datasets::mtcars # Note the spaces in the row names here. lapply(dimnames(x), head)
#> [[1]] #> [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" #> [4] "Hornet 4 Drive" "Hornet Sportabout" "Valiant" #> #> [[2]] #> [1] "mpg" "cyl" "disp" "hp" "drat" "wt" #>
hasValidDimnames(x)
#> [1] FALSE #> Cause of failure: #> x has invalid row names.