[R] Passing characters by .Call

Roger Bivand Roger.Bivand at nhh.no
Tue Feb 3 17:02:55 CET 2004


On Tue, 3 Feb 2004, wolski wrote:

> Hi!
> 
> I try to pass a character by the .Call interface to an c function. And to cast it into  a 
> 
> char *ch;
> 
> Is it possible to do it and how?
> 

Yes. First make sure you have your "Writing R Extensions" handy. Next
decide whether you are going to use Rdefines.h or Rinternals.h. Then read
the chosen header file (in R/includes/). (Rdefines.h includes
Rinternals.h). For example line 255 in Rinternals.h gives

#define STRING_ELT(x,i)	((SEXP *) DATAPTR(x))[i]

I have used incantations like

CHAR(STRING_ELT(x, 0)) 

where x is a character vector - be prepared to use Rprintf() to check that
your assignment works out. 

> 
> Eryk
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Econonic Geography Section, Department of Economics, Norwegian School of 
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, 
Norway, voice: +47-55959355, fax: +47-55959393; Roger.Bivand at nhh.no




More information about the R-help mailing list