[R] Returnin char back through the .Call interface
Roger Bivand
Roger.Bivand at nhh.no
Wed Feb 4 12:17:31 CET 2004
On Wed, 4 Feb 2004, wolski wrote:
> Hi!
>
> My results or error messages are copied in a string and than have to be
> passed back through the .Call interface togheter with numeric results
> What is the best way to allocate storage to a character? (R_alloc?) And
> how to add it to a list? (e.g. allocVector(VECSXP, 9))
>
>
> Help are highly appreciated.
Again, browsing the header files usually helps. A short and probably not
ideal example (COPY_TO_USER_STRING() does the work):
SEXP R_G_get_gisrc_file() {
SEXP ans;
char *gisrc;
PROTECT(ans=NEW_CHARACTER(1));
gisrc = G__get_gisrc_file();
if (gisrc) {
gisrc = G_store(gisrc);
SET_STRING_ELT(ans, 0,
COPY_TO_USER_STRING(gisrc));
} else {
SET_STRING_ELT(ans, 0,
COPY_TO_USER_STRING("empty"));
}
UNPROTECT(1);
return(ans);
}
>
> Eryk
>
>
>
> Ps.
> I tried a with mkChar
> and with
> PROTECT(ral1 = NEW_CHARACTER(1));
>
> ______________________________________________
> 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