[R] C function name garbled
Sigal Blay
sblay at sfu.ca
Wed Sep 8 03:49:56 CEST 2004
On Tue, Sep 07, 2004 at 04:57:57PM -0400, Duncan Murdoch wrote:
> On Tue, 7 Sep 2004 12:46:55 -0700, S Blay <sblay at sfu.ca> wrote :
>
> >I wrote an R wrapper function (phylpro) around a C function
> >(Rphylpro).
> >The first time I'm running my function, it runs with no errors.
> >The second time I'm trying to run it, I get an error message
> >with the first argument to .Call garbled.
> >
> >Set up:
> >> dyn.load("Phylpro.so")
> >> source("phylpro.R")
> >> WinHalfWidth<-30
> >> permReps<-10
> >> breaks<-c(548, 735, 832)
> >
> >First call to phylpro succeeds:
> >> b<-phylpro("simulinfile", breaks, WinHalfWidth, permReps)
> >>
> >
> >Second call to phylpro fails:
> >> b<-phylpro("simulinfile", breaks, WinHalfWidth, permReps)
> >Error in .Call("PSg\bBh\b", input_file =
> >as.character(input_file), breaks = as.integer(breaks), :
> > .Call function name not in load table
> >
> >Check if my C function name is in load table:
> >> is.loaded("Rphylpro")
> >[1] TRUE
> >
> >
> >Any ideas?
>
> It looks to me as though your function is doing something to mess up
> R's internal data. I'd try commenting out the whole body of the
> function, then adding it back gradually to find which part causes the
> trouble.
>
> Duncan Murdoch
I followed your advice - looks like I need some kind of a cast
when I assign the values of a C vector to an R vector. I think.
Below is an example of something that doesn't work -
Can someone give me a hand?
(In the real function, there are also integer and Character
string C vectors...)
Thanks.
#include <R.h>
#include <Rdefines.h>
SEXP myfunc() {
double *corrs;
corrs[0]=3.0;
SEXP Rcorrs;
double *pRcorrs;
PROTECT(Rcorrs = NEW_NUMERIC(1));
pRcorrs = NUMERIC_POINTER(Rcorrs);
pRcorrs[0] = corrs[0];
UNPROTECT(1);
return(R_NilValue);
}
/*
dyn.load("myfunc.so")
func<-function().Call("myfunc")
func()
*/
Run it once, it's ok:
> func()
NULL
Run it twice, not ok:
> func()
Error in .Call(NULL) : function name must be a string (of length 1)
More information about the R-help
mailing list