checkReturnValue {TypeInfo} | R Documentation |
This function is the counterpart to checkArgs
in the type validation for an R function.
When called, either implicitly or explicitly when the function
returns, it attempts to determine whether the value being
returned by the function call is valid relative
to the type information of the function and the call itself.
Specifically, it uses the signature of the current call to the
function if it is available (returned by checkArgs
)
to see if it has a specified return type. If so,
it compares the return value to that.
Otherwise, it checks to see if the return type for the
overall type info object (not just the specific type signature
for the call) is specified and then uses that to validate the
type. If neither is specified, then the value is not validated
and the value returned.
checkReturnValue(returnType, returnJump, sig, f = sys.function(-1))
returnType |
the specifiedtype of the return value. |
returnJump |
this is a very special value which is a call to
return the value of value . It must be explicitly given
in the call to checkReturnValue and is used
to ensure that the return from checkReturnValue
returns from the calling function also in the case
that the value is valid. This is a piece of magic in R
that is very powerful using the lazy evaluation of the
arguments that allows us to return from the place that the
return call was specified.
|
sig |
the signature corresponding to the call of the function
f . This should have a returnType slot
that contains class information or an expression. Otherwise,
the value is taken from the TypeSpecification-class
object for the entire function and its returnType slot.
|
f |
the function object whose return value is to be validated.
It is from this that we get the type info via typeInfo . |
If the validation takes place and is successful
or simply doesn't take place because no returnType
is
available, the return value is value
.
Otherwise, if the validation fails, an error is raised.
This is a prototype to illustrate the idea. It might be done in C code in the future within the R interpreter.
Duncan Temple Lang <duncan@wald.ucdavis.edu>
checkArgs
TypeSpecification-class