I am writing an R function, and I want to make sure that the argument of my R function is of a certain class (eg, "matrix").
What is the best way to do this?
Say I have a function "foo" which computes the inverse of a matrix:
foo <- function(x)
{
# I want to make sure x is of type "matrix"
solve(x)
}
How can I say - as you might in C - function(matrix x)
to denote that "x
must be of type matrix
, and if it isn't, then return an error"?