Skip to content
Prev 201759 / 398503 Next

Does nargin and nargout work with R functions?

Hi,

I think you can use match.call() to retrieve the number of arguments
passed to a function (see below), but I don't think nargout makes
sense in R like it does in Matlab.

foo <- function(...){

  print(match.call())
  nargin <- length(as.list(match.call())) -1
  print(nargin)
}

foo(a=1, b=2)
foo()
foo(1:3, a=2, c=3)

HTH,

baptiste

2009/11/26 Jason Rupert <jasonkrupert at yahoo.com>: