From |uke-t|erney @end|ng |rom u|ow@@edu  Mon Jun 17 19:38:14 2019
From: |uke-t|erney @end|ng |rom u|ow@@edu (Tierney, Luke)
Date: Mon, 17 Jun 2019 17:38:14 +0000
Subject: [Rd] [External] Re:  R C API resize matrix
In-Reply-To: <D7E7A385-9A9D-4933-9798-1B19AEC47577@R-project.org>
References: <CAL0QV_NPf1NzMJbscLc3QirJcAfG=Ks9ecXPbykk--kFmT_0fw@mail.gmail.com>
 <D7E7A385-9A9D-4933-9798-1B19AEC47577@R-project.org>
Message-ID: <alpine.DEB.2.21.1906171234020.4155@luke-Latitude-7480>

On Mon, 17 Jun 2019, Simon Urbanek wrote:

> Matrix is just a vector with the dim attribute. Assuming it is not referenced by anyone, you can set any values to the dim attribute. As for the vector, you can use SET_LENGTH() to shorten it - but I'm not sure how official it is - it was originally designed to work, but there were abuses of TRUELENGTH so not sure where we stand now (shortened vectors used to fool the garbage collector as far as object sizes go). I wouldn't do it unless you're dealing with rally huge matrices.

Don't do that. SET_LENGTH isn't part of the API and using it outside
specific internal code confuses the garbage collector.

There is support for a growable vector but it's not a at a point where
the interface is stable enough to be used in packages. So again please
don't go there.

Also for a matrix unless you are just dropping trailing columns you
would have to move data in memory.

Best,

luke

>
> Cheers,
> Simon
>
>
>> On Jun 14, 2019, at 5:31 PM, Morgan Morgan <morgan.emailbox at gmail.com> wrote:
>>
>> Hi,
>>
>> Is there a way to resize a matrix defined as follows:
>>
>> SEXP a = PROTECT(allocMatrix(INTSXP, 10, 2));
>> int *pa  = INTEGER(a)
>>
>> To row = 5 and col = 1 or do I have to allocate a second matrix "b" with
>> pointer *pb and do a "for" loop to transfer the value of a to b?
>>
>> Thank you
>> Best regards
>> Morgan
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



[Rd] [External] Re: R C API resize matrix
Tierney, Luke