[R] Sending "..." to a C external
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Sat Aug 23 13:53:23 CEST 2008
2008/8/22 Emmanuel Charpentier <emm.charpentier at free.fr>:
> Le vendredi 22 août 2008 à 15:16 -0400, John Tillinghast a écrit :
>> I'm trying to figure this out with "Writing R Extensions" but there's not a
>> lot of detail on this issue.
>> I want to write a (very simple really) C external that will be able to take
>> "..." as an argument.
>> (It's for optimizing a function that may have several parameters besides the
>> ones being optimized.)
>
> !!! That's a hard one. I have never undertaken this kind of job, but I expect
> that your "..." argument, if you can reach it from C (which I don't know) will
> be bound to a Lisp-like structure, notoriously hard to decode in C. Basically,
> you'll have to create very low level code (an duplicate a good chunk of the R
> parser-interpreter...).
>
> I'd rather treat the "..." argument in a wrapper that could call the relevant
> C function with all arguments interpreted and bound... This wrapper would
> probably be an order of magnitude slower than C code, but two orders of magnitude
> easier to write (and maintain !). Since "..." argument parsing would be done *once*
> before the "grunt work" is accomplished by C code, the slowdown would (probably)
> be negligible...
I think you're overstating the problem somewhat! Everything you need
to process "..." in C is pretty much in the showArgs function in the
R-ext help. The problem is that John's not told us what his error was!
It works for me:
> showArgs(x=2,y=3,z=4)
[1] 'x' 2.000000
[2] 'y' 3.000000
[3] 'z' 4.000000
NULL
> showArgs(x=2,y=3,z="s")
[1] 'x' 2.000000
[2] 'y' 3.000000
[3] 'z' s
NULL
But I can get an error if I don't name an argument:
> showArgs(x=2,y=3,"s")
[1] 'x' 2.000000
[2] 'y' 3.000000
Error in showArgs(x = 2, y = 3, "s") :
CHAR() can only be applied to a 'CHARSXP', not a 'NULL'
But that's just because the C doesn't check for this.
Is that what you're getting? What errors are you getting?
Barry
[this was on an R 2.7.0 I had kicking around, so maybe changed for
later versions...]
More information about the R-help
mailing list