[R] RE: [Rd] too many arguments in foreign function call
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Jul 17 02:09:52 CEST 2001
"Warnes, Gregory R" <gregory_r_warnes at groton.pfizer.com> writes:
> Brian, do you really expect everyone to get in the habit of writing C code
> to translate R SEXP into appropriate C or Fortran objects? For the large
> number of cases where the objects to be passed to and from C/Fortran are
> simple scalars and vectors it really makes sense to keep the code to do the
> translation in a standard library routine like do_dotcode(). This keeps the
> bugs down to a minimum and makes it as easy as possible for people to
> interface code.
>
> All I suggested doing was removing the arbitrary restriction to <= 65
> parameters. I even provided the code. What's the problem?
Some anxiety that there might be platforms that really don't allow
many parameters, I suppose. (As opposed to the arbitrary limit imposed
by R, essentially caused by the programmer giving up after
case 65:
retval = (SEXP)fun(
cargs[0], cargs[1], cargs[2], cargs[3], cargs[4],
cargs[5], cargs[6], cargs[7], cargs[8], cargs[9],
cargs[10], cargs[11], cargs[12], cargs[13], cargs[14],
cargs[15], cargs[16], cargs[17], cargs[18], cargs[19],
cargs[20], cargs[21], cargs[22], cargs[23], cargs[24],
cargs[25], cargs[26], cargs[27], cargs[28], cargs[29],
cargs[30], cargs[31], cargs[32], cargs[33], cargs[34],
cargs[35], cargs[36], cargs[37], cargs[38], cargs[39],
cargs[40], cargs[41], cargs[42], cargs[43], cargs[44],
cargs[45], cargs[46], cargs[47], cargs[48], cargs[49],
cargs[50], cargs[51], cargs[52], cargs[53], cargs[54],
cargs[55], cargs[56], cargs[57], cargs[58], cargs[59],
cargs[60], cargs[61], cargs[62], cargs[63], cargs[64]);
break;
There's obviously no portable and neat way of doing variable length
argument lists.)
You don't need to go via SEXPs to solve your problem, and in fact not
even to C. You could for instance use (pardon, my Fortran is getting
rusty):
subroutine doit(work, p, i)
double precision work(1)
integer p(59), i(25)
call myfun(work(1),work(p(1)),work(p(2)),....,work(p(59)),
+ i(1),...,i(25))
return
end
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list