From duncan@research.bell-labs.com  Fri Jul 13 12:27:36 2001
From: duncan@research.bell-labs.com (Duncan Temple Lang)
Date: Fri, 13 Jul 2001 07:27:36 -0400
Subject: [Rd] too many arguments in foreign function call
In-Reply-To: <3B4ED524.244367EC@warnes.net>; from greg@warnes.net on Fri, Jul 13, 2001 at 07:01:56AM -0400
References: <3B4ED524.244367EC@warnes.net>
Message-ID: <20010713072736.C20268@jessie.research.bell-labs.com>

Gregory R. Warnes wrote:
> 
> Hi all,
> 
> I've just been working with a piece of fortran code (Leo Breiman's
> random forest code) that needs a lot of arguments.  When I use .Fortran,
> I get the message 'too many arguments in foreign function call'. 
> Neither the help page for .Fortran (actually Foreign) nor "Writing R
> Extensions" explains how many arguments are too many.  
> 
> Looking at the code in src/main/dotcode.c, I see that MAX_ARGS is set to
> 65.  
> 
> While it is possible to work around this limitation, it seems
> arbitrary.  I propose increasing the arbitrary value to 255 and adding
> appropriate documentation to the Foreign manual page.
> 
> Any objections/comments?


Unfortunately, it isn't quite as simple as that.  The code that uses
MAX_ARGS would also need to be extended and that involves adding the
remaining cases to the switch statement in do_dotCode() and
do_dotcall() in src/main/dotcode.c There's no reason why it can't be
done.  Somebody simply has to generate the appropriate code,
presumably programmatically with a little script.  I recall this was
extended in S4, but 64 was adequate for that context.

I imagine that there are some systems limit the number of arguments
one can have to a routine.

 D.


> 
> -Greg
> 
> -----Patch-Starts-Here------
> 
> diff -ur R-1.3.0-orig/src/library/base/man/Foreign.Rd
> R-1.3.0-patched/src/library/base/man/Foreign.Rd
> --- R-1.3.0-orig/src/library/base/man/Foreign.Rd        Sun May  6
> 12:14:16 2001+++ R-1.3.0-patched/src/library/base/man/Foreign.Rd     Fri
> Jul 13 06:58:42 2001@@ -20,7 +20,7 @@
>  \arguments{
>    \item{name}{a character string giving the name of a C function or
>      Fortran subroutine.}
> -  \item{\dots}{arguments to be passed to the foreign function.}
> +  \item{\dots}{arguments (maximum of 255) to be passed to the foreign
> function}   \item{NAOK}{if \code{TRUE} then any \code{\link{NA}} or
>      \code{\link{NaN}} or \code{\link{Inf}} values in the arguments are
>      passed on to the foreign function.  If \code{FALSE}, the presence
> of
> Only in R-1.3.0-patched/src/library/base/man: Foreign.Rd~
> diff -ur R-1.3.0-orig/src/main/dotcode.c
> R-1.3.0-patched/src/main/dotcode.c
> --- R-1.3.0-orig/src/main/dotcode.c     Sat Jun  9 19:35:19 2001
> +++ R-1.3.0-patched/src/main/dotcode.c  Fri Jul 13 06:58:56 2001
> @@ -372,7 +372,7 @@
>      return args;
>  }
>  
> -#define MAX_ARGS 65
> +#define MAX_ARGS 255
>  
>  SEXP do_symbol(SEXP call, SEXP op, SEXP args, SEXP env)
>  {
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
_______________________________________________________________

Duncan Temple Lang                duncan@research.bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-3217
700 Mountain Avenue, Room 2C-259  fax:    (908)582-3340
Murray Hill, NJ  07974-2070       
         http://cm.bell-labs.com/stat/duncan
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] too many arguments in foreign function call
Duncan Temple Lang