[Rd] .Call - applying setAttrib(x, R_DimSymbol,
s) to a matrix being an element of a list
Simon Urbanek
simon.urbanek at r-project.org
Thu Mar 17 15:06:22 CET 2005
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
More information about the R-devel
mailing list