TypeInfo
uses checkArgs
internally. This function is used to validate the arguments in a call
to a function that has associated type information about the
parameters. The types for the parameters are currently
given associated with the function via an attribute
"ParameterTypes"
. In the body of the function,
one can call checkArgs
and the specification is
taken and used to compute whether the elements in the call
are compatible with those in the signatures.
There are currently several ways to specify the signatures.
One is as a list of explicit parameter name - class
name pair vectors given as
c(paramName = className, paramName = className, ...)
.
Alternatively, one can use an expression to perform a dynamic test.
For example, one can test the length of an object, e.g.
c(x = length(x) < 4, y = length(y) == length(x))
.
Each expression should return a logical value indicating whether
the expected condition was satisfied.
A third form of specifying signatures is given using class names
for individual parameters and just matching the argument
class to these names. This differs from the first form
because the arguments are not checked simultaneoulsy, but
rather one at a time. The test for a given argument is
whether it is in the named vector of classes.
checkArgs(f = sys.function(1), argNames, args = NULL, forceAll = FALSE, env = sys.frame(1), isMissing = logical(0))
checkArgs
.
TRUE
, then we
evaluate all of the arguments in the call frame of the function
being evaluated whose arguments we are to check. If this is
FALSE
,
This should be a three-level enum to represent
evaluate as needed, evaluate all referenced in any of the
signatures and evaluate all of the arguments now.
f
of class
function
SimultaneousTypeSpecification-class
is provided to this function, the TypedSignature-class
elements are searched sequentially until a matching one is found.
That matching signature is returned. Therefore, the order the
signatures are specified within the
SimultaneousTypeSpecification-class
object is
important. This could change if we wanted. At present, it is up to the author to specify
what they want to have happen. We could use the S4 signature
matching technique when this is finalized and implemented in C code.
typeInfo
bob = function(x, y) {
checkArgs() # Completely unecessary as we don't specify type information.
"Finished"
}
# a call generates a warning to say that there was no type information.
bob()
Run the code above in your browser using DataCamp Workspace