[R] subscripted assignment of grid units

Paul Murrell p.murrell at auckland.ac.nz
Tue Jul 7 22:37:23 CEST 2009


Hi

You have encountered the fact that, while there are "[" methods for grid 
unit objects, there are NOT any "[<-" methods for grid unit objects.

I guess that needs to go (back) onto my todo list.

A workaround for your simple example is ...

unit.c(testUnits[1:2], testUnit2, testUnits[4:5])

... though I can imagine that getting pretty tedious in more complex cases.

Paul


pbarros wrote:
> Hi,
> 
> I want to do subscripted assignment of grid units, but I cannot find a
> straightforward way of doing it (and I have searched all forums and places I
> could think about, including Paul Murrell,s page). The usual subscripted
> assignment operator does replace the numeric part, but does not update the
> attributes. Before I write my own function, manipulating attributes etc I
> would like to know if such a function already exists (I am sure it does).
> What I want to do can be reflected as in the code below:
> 
>  testUnit <- unit(1, "lines")
>> testUnit
> [1] 1lines
>> testUnits <- rep(testUnit, 5)
>> testUnits
> [1] 1lines 1lines 1lines 1lines 1lines
>> testUnit2 <- unit(0.5, "grobwidth", textGrob("Testing"))
>> testUnits[3] <- testUnit2
>> testUnits
> [1] 1lines   1lines   0.5lines 1lines   1lines
> 
> I would like to obtain
> [1] 1lines   1lines   0.5grobwidth 1lines   1lines
> 
> Any tips?
> 
> Thanks,
> Pedro
> --
> View this message in context: http://www.nabble.com/subscripted-assignment-of-grid-units-tp24371172p24371172.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list