Does the input object have syntactically valid names?

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

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

Arguments

x

Object.

.xname

Name of object defined in x. Not intended to be used directly.

Value

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

Note

Updated 2019-08-10.

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: 'x' does not contain valid names: [1] 1, [2] foo bar, [3] foo-bar #> See 'make.names()' for details.
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: 'x' does not contain valid names: [1] Mazda RX4, [2] Mazda RX4 Wag, [3] Datsun 710, [4] Hornet 4 Drive, [5] Hornet Sportabout, [7].... #> See 'make.names()' for details.