Hi All,

The Writing R-extensions document says this on whether I should prefer
.C or .Call:

   "Before you decide to use .Call or .External, you should look at other
alternatives.
First, consider working in interpreted R code; if this is fast enough, this
is normally the
best option. You should also see if using .C is enough. If the task to be
performed in C is
simple enough requiring no call to R, .C suffices. The new interfaces are
relatively recent
additions to S and R, and a great deal of useful code has been written
using just .C before
they were available. The .Call and .External interfaces allow much more
control, but
they also impose much greater responsibilities so need to be used with
care. Neither .Call
nor .External copy their arguments. You should treat arguments you receive
through
these interfaces as read-only."

So I am using .C; I am not referencing R objects in my code and .C appears
simpler for me
to use.  First, am I correct about using .C?

Next, my C function has a char* argument and I cannot figure out how to
pass that from my R
code.  The argument specifies the mode in which computations will be
performed by the
function; it is a single character actually.  (The code was written as a
standalone program
and I want to make it into an R package.)  For the R character type the doc
lists char** as
equivalent.  I am not following that at all... That is used for an array of
pointers
(to chars) not the chars themselves.  I am confused.

Finally, I read that .C does a lot of copying of the arguments on call and
return.  How can
I avoid that? Is DUP=FALSE to be used for that?  I am hesitant because I
read that DUP=FALSE
is not to be used with characters and further that I should treat the
arguments read-only in the
C-code. (and I am told several times that it is dangerous...)  In my code a
matrix is passed
to the C code (an initial value) and it is modified (updated) by the C code
to be returned.
So I have something like this presently:

tmp <- .C("foo", DUP = FALSE, NAOK = TRUE, as.character('d'), X =
as.double(X), as.double(Y))

where Y will not be modified by foo() and X is changed and treated as a
return value.

Your insight would be appreciated.
-Matyas

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to