[R] converting R objects to C types in .Call

Faheem Mitha faheem at email.unc.edu
Mon Jan 24 18:58:15 CET 2005


Dear People,

I'm trying to write an R wrapper for a C++ library, using .Call. I've 
never used .Call before. I'm currently having some difficulties converting 
a R character string to a C one.

Here is a little test program.

#include <R.h>
#include <Rinternals.h>
#include <stdio.h>

SEXP testfn(SEXP chstr)
{
   char * charptr = CHAR(chstr);
   printf("%s", charptr);
}

This compiles without problems, but when I try to run this as

> .Call("testfn", "foo")

I get a segmentation fault.

I am sure I am making an obvious mistake, but can someone help me to sort 
it out? Thanks in advance. Please cc me, I'm not subscribed.

                                                              Faheem.




More information about the R-help mailing list