Skip to content
Prev 202070 / 398503 Next

Does nargin and nargout work with R functions?

This works great. 

Thanks for your help. 



----- Original Message ----
From: baptiste auguie <baptiste.auguie at googlemail.com>
To: Jason Rupert <jasonkrupert at yahoo.com>
Cc: R-help <R-help at r-project.org>
Sent: Thu, November 26, 2009 11:08:57 AM
Subject: Re: [R] 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>: