On Jun 18, 2009, at 16:34 , Kynn Jones wrote:

I was surprised to see that there is a ScalarInteger function in
Rinlinedfuns.h, but nothing like ScalarLong.

How can one create an R-integer from a C long?


There is no such thing as "long" in R (*), so one cannot make a "scalar long" vector in R. But to answer your question (how to create "R-integer" - interpreted as "integer vector of length one") it's simply
ScalarInteger((int) myLong)

(*) - on 32-bit systems long and int are equivalent, so the conversion is lossless, on 64-bit systems there is no way to store a "long" in R integer without loss of precision. The only lossless way on 64-bit systems is to store it in a raw vector of 8 bytes (but then there's not much you can do with it ...). For practical purposes it is usually sufficient to convert it to double (real vector in R) since you have at least guaranteed 52-bit precision (technically even more) and can perform the usual operations on it.

Cheers,
Simon

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to