checkMethodsNumArgs: Check the number of arguments for a native method/routine

checkMethodsNumArgsR Documentation

Check the number of arguments for a native method/routine

Description

This function is used to verify that an R function being used as a proxy for a C/C++ routine or method has the approrpriate number of parameters so that calls to it from the intermediate (programmatically generated) C/C++ code will not fail because there are too many values being passed to it. So in short, this just ensures that the R function has enough parameters, including the ... parameter.

This is a vectorized function. It takes the number of arguments expected as a vector and then a collection of functions via the ... parameter or via the funs

See asFunctionPointer.

Usage

checkMethodsNumArgs(expected, ..., .funs = list(...))

Arguments

expected

an vector giving the number of parameters for the methods of interest. This can be a named vector in which case the names are matched with those of .funs.

...

one or more R functions. These can be named arguments and the names are used to find the expected number of parameters in expected.

.funs

an alternative way to specify the R functions which is convenient if they are already in a list.

Note

See asFunctionPointer. The code could be shared by these two.

Author(s)

Duncan Temple Lang

Examples

  a = function(x, y) { }
  b = function(x, y, ...) { }

  checkMethodsNumArgs(c(2, 4), a, b)

  fail = function(x, y) { }
  try(checkMethodsNumArgs(c(2, 4), a, fail))

  try(checkMethodsNumArgs(c(b = 2, f = 4), b = b, f = fail))

omegahat/RAutoGenRunTime documentation built on Jan. 12, 2023, 9:19 p.m.