[R] Calling C++ code fom R --How to export C++ "unsigned" integer to R?
Duncan Murdoch
murdoch at stats.uwo.ca
Mon May 8 20:56:03 CEST 2006
On 5/8/2006 2:44 PM, Boom 2k1 wrote:
> Hello all,
>
> Is there a way to export C++ "unsigned" integer to R? (I am trying to parse
> files in "BPMAP" format, and some variables are of type unsigned int (first
> declared in C++) ).
>
> I know that to export signed integer to R,
> I can do the following in C++:
>
> int Some_INTEGER = 5;
>
> int *p_myInt;
> SEXP myInt;
> PROTECT(myInt=NEW_INTEGER(1));
>
> myInt[0] = Some_INTEGER;
>
> UNPROTECT(1);
>
> return myInt;
>
>
> However, it appears that myInt is a signed integer.
>
> I have looked over Rdefines.h and it does not look like there is a
> definition for NEW_UNSIGNED_INTEGER !
R has no type that corresponds to an unsigned integer. You should
convert these to floating point if you want to keep the values. (The
double precision floating point format that R uses stores all 32 bit
unsigned integers exactly. If your compiler defines int to be 64 bits,
you're in trouble, because there is no way to represent all unsigned 64
bit integers in R.)
By the way, generally more technical questions like interfacing to C++
are better in the R-devel list.
Duncan Murdoch
More information about the R-help
mailing list