[R] {grid} plain units with non NULL data arguments

Wolfram Fischer wolfram at fischer-zim.ch
Tue Aug 14 16:28:58 CEST 2007


In help(unit) I read:

     The 'data' argument must be a list when the 'unit.length()'
     is greater than 1.  For example, 'unit(rep(1, 3), c("npc",
     "strwidth", "inches"), data=list(NULL, "my string", NULL))'.

In the newest R-versions it is not anymore allowed to let strings
in the data-argument for plain units, otherwise one gets the
following error:
    Non-NULL value supplied for plain unit

I have some labels. Between them I wanted to set a distance of 1.5 lines.
(I wanted to use that for a grid.layout for a legend:
The space is for the symbols.)

    labels <- c( 'xxxx:', 'a', 'bb', 'ccc', 'dddd', 'eeeee' )
    n <- length( labels )
    s <- as.list( c( labels[1], rep( labels[-1], each=2 ) ) )
    u <- unit( data=s, x=c( 1, rep( c( 1.5, 1 ), n-1 ) ),
        units=c( 'strwidth', rep( c( 'lines', 'strwidth' ), n-1 ) ) )

How can I insert the NULL values into the list ``s''?

To fill every second element of s with NULL, I tried:
    s[ 2 * ( 1 : length( labels[-1] ) ) ] <- NULL
But this deletes every second element.

The following would work:
    s[ 2 * ( 1 : length( labels[-1] ) ) ] <- NA
But unit() does not accept NAs.


Regards - Wolfram



More information about the R-help mailing list