When several supposedly "equivalent" data sets are used to generate variable keys, there may be trouble. If variables with same name have different classes, keyApply might fail when applied to one of the data sets.

keysPoolCheck(keys, col = "class_old", excludere = "TEXT$")

Arguments

keys

A list with variable keys.

col

Name of key column to check for equivalence. Default is "class_old", but "class_new" can be checked as well.

excludere

Exclude variables matching a regular expression (re). Default example shows exclusion of variables that end in the symbol "TEXT".

Value

Data.frame summarizing class differences among keys

Details

This reports on differences in classes among keys. By default, it looks for differences in "class_old", because that's where we usually see trouble.

The output here is diagnostic. The keys can be fixed manually, or the function keysPool can implement an automatic correction.

Author

Paul Johnson

Examples

set.seed(234)
dat1 <- data.frame(x1 = rnorm(100),
                   x2 = sample(c("Male", "Female"), 100, replace = TRUE),
                   x3_TEXT = "A", x4 = sample(1:10000, 100))
dat2 <- data.frame(x1 = rnorm(100), x2 = sample(c("Male", "Female"),
                   100, replace = TRUE),
                   x3_TEXT = sample(1:100, 100),
                   stringsAsFactors = FALSE)
key1 <- keyTemplate(dat1)
key2 <- keyTemplate(dat2)
keys <- list(key1, key2)
keysPoolCheck(keys)
#> [1] name_old   class_old1 class_old2 troublevar
#> <0 rows> (or 0-length row.names)
## See problem in class_old
keysPoolCheck(keys, col = "class_old")
#> [1] name_old   class_old1 class_old2 troublevar
#> <0 rows> (or 0-length row.names)
## problems in class_new
keysPoolCheck(keys, col = "class_new")
#> [1] name_old   class_new1 class_new2 troublevar
#> <0 rows> (or 0-length row.names)
keysPoolCheck(keys, excludere = "TEXT$")
#> [1] name_old   class_old1 class_old2 troublevar
#> <0 rows> (or 0-length row.names)