From simon.urbanek at r-project.org  Thu Mar 17 15:06:22 2005
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu Mar 17 15:06:38 2005
Subject: [Rd] .Call - applying setAttrib(x, R_DimSymbol,
	s) to a matrix being an element of a list
In-Reply-To: <4238DEBD.1090805@ebi.ac.uk>
References: <42386FA6.7040800@ebi.ac.uk>
	<34C019CA-160A-4AFF-B622-CFB95201F5AD@r-project.org>
	<4238DEBD.1090805@ebi.ac.uk>
Message-ID: <455C84D0-365B-47B9-9FFF-F0C5F6F334D0@r-project.org>

Oleg,

On Mar 16, 2005, at 8:34 PM, Oleg Sklyar wrote:

> Sorry, it is always a tradeoff - either to explain or put a 
> relatively large code,

Just posting all R related commands is sufficient ;) - in your case 
that would be the single imgSize alloc and the assignments- but the 
full code is fine, too.

> which also uses non-standard libraries making the code difficult to 
> read. imgSize values are reset in between: see the full code below. 
> The SEXP pointer imgSize stays in tact,

That's the problem. As I said previously - you need to duplicate it or 
alloc new ones. setAttrib of non-NAMED values doesn't copy the value, 
so you're passing the same pointer to all your matrices, so they all 
share the same dimension object. This means that whenever you change 
integers the pointer is pointing at, you change it for all matrices you 
used it in, which is probably not what you intended.

> that's true, but its values are changed (the problem is, they are 
> always the last in the row). I.e. if I have 3 images 40x20, 200x100 
> and 150x75 I will get three matrices of 150x75, but if I omit 
> setAtrib and return vectors I get vectors of different length.

The length of the vector has nothing to do with the dimensions - 
technically. In C you can say "this is a vector of 10 integers and has 
dimension 100x200" - although such matrix is invalid, in C you're free 
to do so. It's up to your code to make sure the dimension and the 
vector length match. In your case, they don't and your code is to blame 
;).

Cheers,
Simon


[Rd] .Call - applying setAttrib(x, R_DimSymbol, s) to a matrix being an element of a list
Simon Urbanek