From dsamperi at DecisionSynergy.com  Tue Oct 25 15:34:24 2005
From: dsamperi at DecisionSynergy.com (Dominick Samperi)
Date: Tue, 25 Oct 2005 09:34:24 -0400
Subject: [Rd] Small issue with R's C API
In-Reply-To: <Pine.LNX.4.61.0510251254220.10299@gannet.stats>
References: <435E1A4D.102@DecisionSynergy.com>
	<Pine.LNX.4.61.0510251254220.10299@gannet.stats>
Message-ID: <435E3460.3020203@DecisionSynergy.com>

Prof Brian Ripley wrote:
> This is nothing to do with the C API: isVector and isMatrix are not 
> part of the API (see Writing R Extensions for what it is).  That's the 
> `issue' here.
>
> On Tue, 25 Oct 2005, Dominick Samperi wrote:
>
>> Consider the R code:
>> mat <- matrix(seq(1,20),4,5)
>> is.matrix(mat) # gives TRUE
>> is.vector(mat) # gives FALSE
>>
>> On the other hand, if mat is passed through the .Call interface the
>> corresponding SEXP (call it smat) satisfies
>> isMatrix(smat)   // TRUE
>> isVector(smat)  // TRUE
>>
>> Consequently, you cannot distinguish matrices from vectors. Looking
>> at the dim attribute of a vector doesn't help because this is garbage.
>
> You can look to see if it has a dim attribute ... you could also look 
> at the C code for is.vector.
The first option here does not seem to work. The code

SEXP dimAttr = getAttrib(smat, R_DimSymbol)

does not set dimAttr to 0 (NULL) wheh smat is actually a vector.



[Rd] Small issue with R's C API
Dominick Samperi