alike(list(integer(), list(character(), logical(1L))), list(1:10, 
    list(letters, c(TRUE, FALSE))))

`length(list(1:10, list(letters, c(TRUE, FALSE)))[[2]][[2]])` should be 1 (is 2)

[1] "`length(list(1:10, list(letters, c(TRUE, FALSE)))[[2]][[2]])` should be 1 (is 2)"

# `NULL` is a wild card when nested within recursive objects

[1] "`mtcars` should be `NULL` (is \"list\")"

iris.fake <- transform(iris, Species = as.character(Species))

# Since `data.frame` are lists, we can compare them recursively:

`iris.fake$Species` should be class "factor" (is "character")

[1] "`iris.fake$Species` should be class \"factor\" (is \"character\")"

iris.fake2 <- transform(iris, Species = factor(Species, levels = `[[<-`(levels(Species), 
    3, "americana")))

# we even check attributes (factor levels must match)!

`levels(iris.fake2$Species)[3]` should be "virginica" (is "americana")

[1] "`levels(iris.fake2$Species)[3]` should be \"virginica\" (is \"americana\")"

# We can use partially specified objects as templates

'data.frame':	0 obs. of  5 variables:
 $ Sepal.Length: num 
 $ Sepal.Width : num 
 $ Petal.Length: num 
 $ Petal.Width : num 
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..:

# any row sample of iris matches our iris template

`names(iris[c(2, 1, 3, 4, 5)])[1]` should be "Sepal.Length" (is "Sepal.Width")

[1] "`names(iris[c(2, 1, 3, 4, 5)])[1]` should be \"Sepal.Length\" (is \"Sepal.Width\")"

alike(matrix(integer(), 3, 3), matrix(1:9, nrow = 3))

alike(matrix(integer(), 3, 3), matrix(runif(9), nrow = 3))

`matrix(runif(9), nrow = 3)` should be type "integer-like" (is "double")

[1] "`matrix(runif(9), nrow = 3)` should be type \"integer-like\" (is \"double\")"

alike(matrix(integer(), 3), matrix(1:12, nrow = 3))

# partial spec, any 3 row integer matrix

alike(matrix(integer(), 3), matrix(1:12, nrow = 4))

`matrix(1:12, nrow = 4)` should have 3 rows (has 4)

[1] "`matrix(1:12, nrow = 4)` should have 3 rows (has 4)"

alike(matrix(logical()), array(rep(TRUE, 8), rep(2, 3)))

`array(rep(TRUE, 8), rep(2, 3))` should be "matrix" (is "array")