Title: | Comparing Objects for Differences |
---|---|
Description: | Functions to compare a model object to a comparison object. If the objects are not identical, the functions can be instructed to explore various modifications of the objects (e.g., sorting rows, dropping names) to see if the modified versions are identical. |
Authors: | Paul Murrell |
Maintainer: | Paul Murrell <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2-6 |
Built: | 2024-12-08 07:04:43 UTC |
Source: | CRAN |
This function applies a commenting scheme to a set of comparisons to produce a set of comments.
commentQuestions(result, ...)
commentQuestions(result, ...)
result |
A set of comparison results, as generated by the
|
... |
One or more commenting schemes, as generated by the
|
A matrix of comments.
Paul Murrell
questionComments
and
compareFiles
modelNames <- c("id", "age", "edu", "class", "IndianMothers") files <- list.files(system.file("example", package="compare"), pattern="^student[0-9]+[.]R$", full.names=TRUE) results <- compareFiles(files, modelNames, system.file("example", "model.R", package="compare"), allowAll=TRUE, resultNames=gsub(".+[/]|[.]R", "", files)) q1comments <- questionComments(c("id", "age", "edu", "class"), comments("class", transformComment("coerced", "'class' is a factor!"))) commentQuestions(results, q1comments)
modelNames <- c("id", "age", "edu", "class", "IndianMothers") files <- list.files(system.file("example", package="compare"), pattern="^student[0-9]+[.]R$", full.names=TRUE) results <- compareFiles(files, modelNames, system.file("example", "model.R", package="compare"), allowAll=TRUE, resultNames=gsub(".+[/]|[.]R", "", files)) q1comments <- questionComments(c("id", "age", "edu", "class"), comments("class", transformComment("coerced", "'class' is a factor!"))) commentQuestions(results, q1comments)
Compare two objects and, if they are not the same, attempt to transform them to see if they are the same after being transformed.
compare(model, comparison, equal = TRUE, coerce = allowAll, shorten = allowAll, ignoreOrder = allowAll, ignoreNameCase = allowAll, ignoreNames = allowAll, ignoreAttrs = allowAll, round = FALSE, ignoreCase = allowAll, trim = allowAll, dropLevels = allowAll, ignoreLevelOrder = allowAll, ignoreDimOrder = allowAll, ignoreColOrder = allowAll, ignoreComponentOrder = allowAll, colsOnly = !allowAll, allowAll = FALSE) compareName(model, compName, ..., ignore.case = TRUE, compEnv = .GlobalEnv)
compare(model, comparison, equal = TRUE, coerce = allowAll, shorten = allowAll, ignoreOrder = allowAll, ignoreNameCase = allowAll, ignoreNames = allowAll, ignoreAttrs = allowAll, round = FALSE, ignoreCase = allowAll, trim = allowAll, dropLevels = allowAll, ignoreLevelOrder = allowAll, ignoreDimOrder = allowAll, ignoreColOrder = allowAll, ignoreComponentOrder = allowAll, colsOnly = !allowAll, allowAll = FALSE) compareName(model, compName, ..., ignore.case = TRUE, compEnv = .GlobalEnv)
model |
The “correct” object. |
comparison |
The object to be compared with the |
equal |
Test for equality if test for identity fails. |
coerce |
If objects are not the same, allow coercion of comparsion to model class. |
shorten |
If the length of one object is less than the other, shorten the longer object. |
ignoreOrder |
Ignore the order of values when comparing. |
ignoreNameCase |
Ignore the case of names when comparing. |
ignoreNames |
Ignore names attributes altogether. |
ignoreAttrs |
Ignore attributes altogether. |
round |
If objects are not the same, allow numbers to be rounded. |
ignoreCase |
Ignore the case of string values. |
trim |
Ignore leading and trailing spaces in string values. |
dropLevels |
If factors are not the same, allow unused levels to be dropped. |
ignoreLevelOrder |
Ignore the order of factor levels. |
ignoreDimOrder |
Ignore the order of dimensions when comparing matrices, arrays, or tables. |
ignoreColOrder |
Ignore the order of columns when comparing data frames. |
ignoreComponentOrder |
Ignore the order of components when comparing lists. |
colsOnly |
Only transform columns (not rows) when comparing data frames. |
allowAll |
Allow any sort of transformation (almost; see Details). |
compName |
A string giving the name of the comparison object. |
... |
Arguments to be passed to |
ignore.case |
Ignore the case of the name when searching for the comparison object. |
compEnv |
An environment within which to search for the comparison object. |
The compare()
function compares two objects for equality.
The arguments
allow for various transformations of the objects (e.g., type
coercion) in order to try and achieve equality.
Specific transformations can be turned on via the appropriate
argument, or the allowAll
argument can be used to
enable all transformations, with the exception of
rounding of numeric values.
The compareName()
function is a wrapper for compare()
that requires the name of the comparison object rather than
the objects itself, plus it allows an environment to be supplied
that contains the actual comparison object. This is useful for the
situation where a particular object with a particular name should have
been generated and allows the generated object to differ from the
desired object in terms of the case of its name.
An object of class "comparison"
.
This is a list. The most important components are result
,
which gives the overall success/failure of the comparison,
and transform
, which describes the transformations
attempted during the comparison (whether they were successful or not).
Paul Murrell
comparison-class
and
compareEqual
obj1 <- c("a", "a", "b", "c") obj2 <- factor(obj1) compare(obj1, obj2, allowAll=TRUE)
obj1 <- c("a", "a", "b", "c") obj2 <- factor(obj1) compare(obj1, obj2, allowAll=TRUE)
Compare two objects for equality, coercing the comparison object to the same class as the model object if necessary beforehand.
compareCoerce(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareCoerce(model, comparison, transform=character(), equal=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
compareCoerce(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareCoerce(model, comparison, transform=character(), equal=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
equal |
Whether to test for equality if the test for identity fails. |
ignoreColOrder |
For data frames, whether to reorder columns by name first. |
ignoreNameCase |
For data frames and lists, whether to ignore the case of names when reordering components by name. |
... |
Arguments passed to |
This function is generic, with methods for logical, integer, numeric, and character vectors, factors, arrays, matrices, tables, data frames, and lists.
The integer and numeric methods use the appropriate special-case coercion for factors.
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compare
and
compareEqual
compareCoerce(letters, factor(letters))
compareCoerce(letters, factor(letters))
Compare two objects and allow for various minor differences between them.
compareEqual(model, comparison, transform = character(), ...) ## S3 method for class 'logical' compareEqual(model, comparison, transform = character(), ...) ## S3 method for class 'numeric' compareEqual(model, comparison, transform = character(), round=FALSE, ...) ## S3 method for class 'character' compareEqual(model, comparison, transform=character(), ignoreCase=FALSE, trim=FALSE, ...) ## S3 method for class 'factor' compareEqual(model, comparison, transform=character(), dropLevels=FALSE, ignoreLevelOrder=FALSE, ...) ## S3 method for class 'matrix' compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'array' compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'table' compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'data.frame' compareEqual(model, comparison, transform=character(), ignoreColOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual) ## S3 method for class 'list' compareEqual(model, comparison, transform=character(), ignoreComponentOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual)
compareEqual(model, comparison, transform = character(), ...) ## S3 method for class 'logical' compareEqual(model, comparison, transform = character(), ...) ## S3 method for class 'numeric' compareEqual(model, comparison, transform = character(), round=FALSE, ...) ## S3 method for class 'character' compareEqual(model, comparison, transform=character(), ignoreCase=FALSE, trim=FALSE, ...) ## S3 method for class 'factor' compareEqual(model, comparison, transform=character(), dropLevels=FALSE, ignoreLevelOrder=FALSE, ...) ## S3 method for class 'matrix' compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'array' compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'table' compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'data.frame' compareEqual(model, comparison, transform=character(), ignoreColOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual) ## S3 method for class 'list' compareEqual(model, comparison, transform=character(), ignoreComponentOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
round |
For numeric vectors,
whether the objects should be rounded before comparison.
If |
ignoreCase |
For character vectors, whether to ignore the case of the strings. |
trim |
For character vectors, whether to ignore leading and trailing white space. |
dropLevels |
For factors, whether to drop unused levels before the comparison. |
ignoreLevelOrder |
For factors, whether to ignore the order of levels. |
ignoreDimOrder |
For matrices, arrays, and tables, whether to reorder of the dimensions by name before the comparison. |
ignoreColOrder |
For data frames, whether to reorder the columns by name before the comparison. |
ignoreComponentOrder |
For lists, whether to reorder the components by name before the comparison. |
ignoreNameCase |
For data frames and lists, whether to ignore the case of names when reordering components by name. |
... |
Other arguments controlling the comparison. |
recurseFun |
For data frames, the function to use to compare the columns of the data frames. For lists, the function used to compare the components of the list. |
This function compares two objects for identity (using
identical()
), then if that fails and equal=TRUE
,
compares the objects for equality. The arguments allow for
various relaxations on what “equal” means.
For numeric vectors, the comparison uses all.equal()
to allow for differences in floating-point representation.
The round
argument also allows for much more lenient
comparisons. The round
argument can also be a function,
e.g., floor()
(see other examples below).
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compareEqual(letters, paste(" ", letters, " "), trim=TRUE) compareEqual(c(.1, 1, 10), c(.13, 1.3, 13), round=function(x) { signif(x, 1) })
compareEqual(letters, paste(" ", letters, " "), trim=TRUE) compareEqual(c(.1, 1, 10), c(.13, 1.3, 13), round=function(x) { signif(x, 1) })
Generate objects by running code from one or more files then compare the resulting objects to a set of model objects, allowing for and reporting on minor differences.
compareFile(filename, modelNames, modelCode = NULL, modelSave = NULL, modelAnswers = NULL, round = FALSE, ...) compareFiles(filenames, modelNames, modelCode=NULL, modelSave=NULL, resultNames=filenames, ...)
compareFile(filename, modelNames, modelCode = NULL, modelSave = NULL, modelAnswers = NULL, round = FALSE, ...) compareFiles(filenames, modelNames, modelCode=NULL, modelSave=NULL, resultNames=filenames, ...)
filename |
The name of a file containing R code. |
filenames |
A vector of names of files containing R code. |
modelNames |
A vector of names of objects of interest that should be generated by the code in the file(s). |
modelCode |
The name of a file that contains R code to generate model objects. |
modelSave |
The name of a binary file that can be used to load model objects. |
modelAnswers |
A list containing model objects. |
round |
A logical indicating whether to round, or an integer indicating how many digits to round to, or a function of one argument (that performs something like rounding), or a named list of any of those. |
resultNames |
A vector of names to be used to identify the results from different files. |
... |
For |
The compareFile()
function is useful for comparing several
pairs of objects at once, where the comparison objects are generated
by running R code from a file and the model objects can be generated
in a number of ways.
The compareFiles()
function extends this to comparing the same
set of model objects to several different sets of comparison objects
(where each set of comparison objects is generated from a separate
file of R code).
For generating model objects, if a binary file is specified, that is
used in preference to source code; if a list of objects is provided,
that is used; and if no model objects are specified, they are
taken from the global workspace (using modelNames
).
The round argument may be a named list so that different rounding is applied to different comparisons.
compareFile()
returns an object of class
"comparisonList"
, which is just a list of "comparison"
objects.
compareFiles()
returns an object of class
"comparisonListList"
. This is just a list of
"comparisonList"
objects, but a print method is defined to make
the display of this object a little more sane.
Paul Murrell
modelNames <- c("id", "age", "edu", "class", "IndianMothers") compareFile(system.file("example", "student1.R", package="compare"), modelNames, system.file("example", "model.R", package="compare"))
modelNames <- c("id", "age", "edu", "class", "IndianMothers") compareFile(system.file("example", "student1.R", package="compare"), modelNames, system.file("example", "model.R", package="compare"))
This function is just a wrapper for the identical()
function to
determine whether two objects are identical. Its usefulness
is in being able to be combined with other functions in the
compare package that
perform much more relaxed comparisons.
compareIdentical(model, comparison, transform = character(), ...)
compareIdentical(model, comparison, transform = character(), ...)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
... |
Allows arguments that are only relevant to other comparison functions. |
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compare
and
compareEqual
compareIdentical(1:10/10, 1:10/10) compareIdentical(1:10/10, 3:12/10 - 2/10)
compareIdentical(1:10/10, 1:10/10) compareIdentical(1:10/10, 3:12/10 - 2/10)
Compare two objects for equality, ignoring any attributes if necessary beforehand.
compareIgnoreAttrs(model, comparison, transform = character(), equal = TRUE, ...)
compareIgnoreAttrs(model, comparison, transform = character(), equal = TRUE, ...)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
equal |
Whether to test for equality if the test for identity fails. |
... |
Arguments passed to |
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compare
and
compareEqual
model <- list(a=1:26, b=letters) comparison <- model attr(comparison, "test") <- "test" compareIgnoreAttrs(model, comparison)
model <- list(a=1:26, b=letters) comparison <- model attr(comparison, "test") <- "test" compareIgnoreAttrs(model, comparison)
Compare two objects for equality, ignoring the case of name attributes, or ignoring name attributes altogether, if necessary beforehand.
compareIgnoreNameCase(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareIgnoreNameCase(model, comparison, transform=character(), equal=TRUE, colsOnly=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...) compareIgnoreNames(model, comparison, transform=character(), equal=TRUE, ...) ## S3 method for class 'data.frame' compareIgnoreNames(model, comparison, transform=character(), equal=TRUE, colsOnly=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
compareIgnoreNameCase(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareIgnoreNameCase(model, comparison, transform=character(), equal=TRUE, colsOnly=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...) compareIgnoreNames(model, comparison, transform=character(), equal=TRUE, ...) ## S3 method for class 'data.frame' compareIgnoreNames(model, comparison, transform=character(), equal=TRUE, colsOnly=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
equal |
Whether to test for equality if the test for identity fails. |
colsOnly |
Only ignore (case of) column names (NOT row names). |
ignoreColOrder |
For data frames and lists, sort the columns or components by name before ignoring the case of names. |
ignoreNameCase |
When reordering the columns or components by
name (i.e., when |
... |
Arguments passed to |
These functions are generic, with specific methods for data frames and lists.
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compare
and
compareEqual
model <- data.frame(x=1:26, y=letters, z=factor(letters), stringsAsFactors=FALSE) comparison <- data.frame(a=1:26, b=letters, c=factor(letters), stringsAsFactors=FALSE) compareIgnoreNames(model, comparison)
model <- data.frame(x=1:26, y=letters, z=factor(letters), stringsAsFactors=FALSE) comparison <- data.frame(a=1:26, b=letters, c=factor(letters), stringsAsFactors=FALSE) compareIgnoreNames(model, comparison)
Compare two objects for equality, sorting them if necessary beforehand.
compareIgnoreOrder(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareIgnoreOrder(model, comparison, transform=character(), equal=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
compareIgnoreOrder(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareIgnoreOrder(model, comparison, transform=character(), equal=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
equal |
Whether to test for equality if the test for identity fails. |
ignoreColOrder |
For data frames, whether to reorder columns by name first. |
ignoreNameCase |
For data frames and lists, whether to ignore the case of names when reordering components by name. |
... |
Arguments passed to |
This function is generic, with specific methods for arrays, matrices, tables, and data frames.
For arrays, matrices, and tables, the dimensions are sorted (by dimnames). For data frames, the rows are sorted, not the columns.
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compare
and
compareEqual
compareIgnoreOrder(1:10, 10:1)
compareIgnoreOrder(1:10, 10:1)
Compare two objects for equality, shortening either one if necessary beforehand.
compareShorten(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareShorten(model, comparison, transform=character(), equal=TRUE, colsOnly=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
compareShorten(model, comparison, transform = character(), equal = TRUE, ...) ## S3 method for class 'data.frame' compareShorten(model, comparison, transform=character(), equal=TRUE, colsOnly=TRUE, ignoreColOrder=FALSE, ignoreNameCase=FALSE, ...)
model |
The “correct” object. |
comparison |
The object to be compared with the |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
equal |
Whether to test for equality if the test for identity fails. |
colsOnly |
Whether to only drop extra columns (not rows) when comparing data frames. |
ignoreColOrder |
For data frames, whether to reorder columns by name first. |
ignoreNameCase |
For data frames and lists, whether to ignore the case of names when reordering components by name. |
... |
Arguments passed to |
This function checks whether the two objects being compared are
of the same size and, if they are not, it shrinks the larger one.
Then the two objects are compared using compareIdentical()
and, if that fails and equal=TRUE
, using compareEqual()
.
This function is generic, with specific methods for arrays, matrices, tables, and data frames.
For vectors, extra elements are dropped from the longer object.
For data frames, extra columns, (and, if
colsOnly=FALSE
, extra rows) are dropped. For lists,
extra components are dropped. For arrays, extra dimensions are
dropped. For matrices, the comparison
is forced to be
two-dimensional. For tables, extra dimensions are collapsed
(using sum()
).
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compare
and
compareEqual
compareShorten(1:5, 1:10) compareShorten(matrix(1:10, ncol=2), array(1:100, dim=c(5, 2, 10)))
compareShorten(1:5, 1:10) compareShorten(matrix(1:10, ncol=2), array(1:100, dim=c(5, 2, 10)))
This class is used to represent the result of a comparison between two objects.
It is just a list, with the following components:
Logical value indicating whether the comparison succeeded (the objects were the same).
Character vector of descriptions of any transformations that have been applied to the objects being compared.
The transformed model object.
The transformed comparison object.
The partially transformed model object.
The partially transformed comparison object.
The transformations that have been applied
to the objects being compared, except for any
transformations that were applied during the test for equality
(i.e., by compareEqual()
).
isTRUE(x) transforms(comp)
isTRUE(x) transforms(comp)
x , comp
|
A comparison object. |
Partial values in the result of a comparison are useful for when a
comparison fails, but a subsequent comparison will be attempted, i.e.,
for daisy-chaining the various compareSomething()
functions,
i.e., what compare()
does.
isTRUE()
returns a logical value, based on the comparison
result
.
transforms()
returns a character vector of transformation
descriptions.
Paul Murrell
compare
and
compareEqual
isTRUE(compareIgnoreOrder(1:10, 10:1)) transforms(compareIgnoreOrder(1:10, 10:1))
isTRUE(compareIgnoreOrder(1:10, 10:1)) transforms(compareIgnoreOrder(1:10, 10:1))
This function applies a marking scheme to a set of comparisons to produce a set of marks.
markQuestions(result, ...)
markQuestions(result, ...)
result |
A set of comparison results, as generated by the
|
... |
One or more marking schemes, as generated by the
|
A matrix of marks.
Paul Murrell
questionMarks
and
compareFiles
modelNames <- c("id", "age", "edu", "class", "IndianMothers") files <- list.files(system.file("example", package="compare"), pattern="^student[0-9]+[.]R$", full.names=TRUE) results <- compareFiles(files, modelNames, system.file("example", "model.R", package="compare"), allowAll=TRUE, resultNames=gsub(".+[/]|[.]R", "", files)) q1 <- questionMarks(c("id", "age", "edu", "class"), maxMark=2, rule("id", 1), rule("age", 1), rule("edu", 1), rule("class", 1, transformRule("coerced", 1))) q2 <- questionMarks("IndianMothers", maxMark=1, rule("IndianMothers", 1)) markQuestions(results, q1, q2)
modelNames <- c("id", "age", "edu", "class", "IndianMothers") files <- list.files(system.file("example", package="compare"), pattern="^student[0-9]+[.]R$", full.names=TRUE) results <- compareFiles(files, modelNames, system.file("example", "model.R", package="compare"), allowAll=TRUE, resultNames=gsub(".+[/]|[.]R", "", files)) q1 <- questionMarks(c("id", "age", "edu", "class"), maxMark=2, rule("id", 1), rule("age", 1), rule("edu", 1), rule("class", 1, transformRule("coerced", 1))) q2 <- questionMarks("IndianMothers", maxMark=1, rule("IndianMothers", 1)) markQuestions(results, q1, q2)
These functions are used to specify how the result of a comparison between two objects should be converted to a set of comments for feedback.
questionComments(answerNames, ...) comments(answerName, ...) transformComment(pattern, comment)
questionComments(answerNames, ...) comments(answerName, ...) transformComment(pattern, comment)
answerNames |
The names of objects that have been compared. |
answerName |
The name of one object that has been compared. |
pattern |
A regular expression to search for within the comparison transformations. |
comment |
A comment to record if the regular expression is matched. |
... |
For |
These functions are used to define a commenting scheme. The
function commentQuestions()
can then be used to apply
the results to a set of comparisons, as generated by
compareFiles()
.
An object of class "questionComments"
.
Paul Murrell
commentQuestions
and
compareFiles
# Comment a comparison involving several objects # Start with a comment of 1 and deduct 1 if the comparison failed questionComments(c("id", "age", "edu", "class"), comments("class", transformComment("coerced", "'class' is a factor!")))
# Comment a comparison involving several objects # Start with a comment of 1 and deduct 1 if the comparison failed questionComments(c("id", "age", "edu", "class"), comments("class", transformComment("coerced", "'class' is a factor!")))
These functions are used to specify how the result of a comparison between two objects should be converted to a numeric mark.
questionMarks(answerNames, maxMark, ...) rule(answerName, falseMark, ...) transformRule(pattern, mark)
questionMarks(answerNames, maxMark, ...) rule(answerName, falseMark, ...) transformRule(pattern, mark)
answerNames |
The names of objects that have been compared. |
maxMark |
The maximum mark for the question. |
answerName |
The name of one object that has been compared. |
falseMark |
How many marks to deduct if the comparison result
was |
pattern |
A regular expression to search for within the comparison transformations. |
mark |
How many marks to deduct if the regular expression is matched. |
... |
For |
These functions are used to define a marking scheme. The
function markQuestions()
can then be used to apply
the results to a set of comparisons, as generated by
compareFiles()
.
An object of class "questionMarks"
.
Paul Murrell
markQuestions
and
compareFiles
# Check a comparison involving an object called 'IndianMothers' # Start with a mark of 1 and deduct 1 if the comparison failed questionMarks("IndianMothers", maxMark=1, rule("IndianMothers", 1)) # Check comparisons involving several objects # Start with a mark of 2, for each unsuccessful comparison # deduct 1 mark, and if a comparison involving the object # 'class' includes a coercion transformation, deduct 1 mark. questionMarks(c("id", "age", "edu", "class"), maxMark=2, rule("id", 1), rule("age", 1), rule("edu", 1), rule("class", 1, transformRule("coerced", 1)))
# Check a comparison involving an object called 'IndianMothers' # Start with a mark of 1 and deduct 1 if the comparison failed questionMarks("IndianMothers", maxMark=1, rule("IndianMothers", 1)) # Check comparisons involving several objects # Start with a mark of 2, for each unsuccessful comparison # deduct 1 mark, and if a comparison involving the object # 'class' includes a coercion transformation, deduct 1 mark. questionMarks(c("id", "age", "edu", "class"), maxMark=2, rule("id", 1), rule("age", 1), rule("edu", 1), rule("class", 1, transformRule("coerced", 1)))
Evaluate R code from a file within a local environment and return a list of objects of interest.
sourceFile(filename, modelNames)
sourceFile(filename, modelNames)
filename |
The name of a file containing R code. |
modelNames |
The names of objects of interest that should be generated by the R code in the file and that we want returned. |
A list containing one component for each name in modelNames
.
Paul Murrell
modelNames <- c("id", "age", "edu", "class", "IndianMothers") sourceFile(system.file("example", "student1.R", package="compare"), modelNames)
modelNames <- c("id", "age", "edu", "class", "IndianMothers") sourceFile(system.file("example", "student1.R", package="compare"), modelNames)