This project is being integrated into vetr. Please submit but reports, feature requests, etc., on that project's home page.
alike is similar to
all.equal from base R except it only compares object structure. As with
all.equal, the first argument (
target) must be matched by the second (
library(alike) alike(integer(5), 1:5) # different values, but same structure ##  TRUE alike(integer(5), 1:4) # wrong size ##  "`1:4` should be length 5 (is 4)" alike(integer(26), letters) # same size, but different types ##  "`letters` should be type \"integer-like\" (is \"character\")"
alike only compares structural elements that are defined in
target (a.k.a. the template). This allows "wildcard" templates. For example, we consider length zero vectors to have undefined length so those match vectors of any length:
alike(integer(), 1:5) ##  TRUE alike(integer(), 1:4) ##  TRUE alike(integer(), letters) # type is still defined and must match ##  "`letters` should be type \"integer-like\" (is \"character\")"
Similarly, if a template does not specify an attribute, objects with any value for that attribute will match:
alike(list(), data.frame()) # a data frame is a list with a attributes ##  TRUE alike(data.frame(), list()) # but a list does not have the data.frame attributes ##  "`list()` should be class \"data.frame\" (is \"list\")"
As an extension to the wildcard concept, we interpret partially specified core R attributes. Here we allow any three column integer matrix to match:
mx.tpl <- matrix(integer(), ncol=3) # partially specified matrix alike(mx.tpl, matrix(sample(1:12), nrow=4)) # any number of rows match ##  TRUE alike(mx.tpl, matrix(sample(1:12), nrow=3)) # but column count must match ##  "`matrix(sample(1:12), nrow = 3)` should have 3 columns (has 4)"
or a data frame of arbitrary number of rows, but same column structure as
iris.tpl <- iris[0, ] # no rows, but structure is defined alike(iris.tpl, iris[1:10, ]) # any number of rows match ##  TRUE alike(iris.tpl, CO2) # but column structure must match ##  "`names(CO2)` should be \"Sepal.Length\" (is \"Plant\")"
"alikeness" is complex to describe, but should be intuitive to grasp. We recommend you look at the examples in the documentation for
alike to get a sense for alikeness. If you want to understand the specifics, read on.
NOTE: this is a snippet from the vignette; we recommend you look at the actual vignette as it will show the evaluated R expressions and the links will work.
Currently this package is only available from github:
library(devtools) install_github("brodieg/cstringr") # required dependency install_github("brodieg/alike")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.