RE: [Rd] type of list elements in .Call

From: Huntsinger, Reid <reid_huntsinger_at_merck.com>
Date: Tue 01 Feb 2005 - 04:42:05 EST


This just means that R doesn't currently do anything complicated when you ask for a pointer to the data in an R vector object. But that doesn't matter; the behavior of REAL etc doesn't depend on that.

Note that INTEGER, REAL, etc just give you pointers of type int *, double *, etc. It's up to you to make sure that a particular use makes sense or you'll get garbage at best. As discussed in the manual, you can either do this on the R side, or in C: first check the type of the object, then coerce if that makes sense and is necessary, and handle errors as you see fit.

Coercion between types requires a copy, in general, so you need to explicitly ask for that.

Reid Huntsinger

-----Original Message-----
From: r-devel-bounces@stat.math.ethz.ch
[mailto:r-devel-bounces@stat.math.ethz.ch] On Behalf Of Faheem Mitha Sent: Monday, January 31, 2005 10:52 AM
To: Prof Brian Ripley
Cc: r-devel@stat.math.ethz.ch
Subject: Re: [Rd] type of list elements in .Call

On Mon, 31 Jan 2005, Prof Brian Ripley wrote:

> This is covered, copiously, in the examples in `Writing R Extensions'.
> Hint: search for coerceVector.

I see. I thought that INTEGER and its relatives did coercion too, but now I see that is not stated anywhere.

Eg. REAL is first used in "Writing R Extensions" in 4.7.1 as in

REAL(ab)[0] = 123.45
...

and I cannot find a discussion about what it does previous to that, or indeed afterwards.

In Rinternals header file, it says

/* Under the generational allocator the data for vector nodes comes

    immediately after the node structure, so the data address is a     known ofset from the node SEXP. */

This does not mean much to me. Perhaps a short comment in the documentation would be helpful, if not already present.

                                                                   Faheem.

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

R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Feb 01 04:11:01 2005

This archive was generated by hypermail 2.1.8 : Tue 01 Feb 2005 - 04:24:33 EST