[R] {grid} plain units with non NULL data arguments
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Aug 14 16:50:40 CEST 2007
On Tue, 14 Aug 2007, Wolfram Fischer wrote:
> 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.
A value of list(NULL) is correct for inserting NULLs into lists.
(More generally to substitute in a list you need a list value.)
> The following would work:
> s[ 2 * ( 1 : length( labels[-1] ) ) ] <- NA
> But unit() does not accept NAs.
More to the point, it does not accept logical vectors as NULL values.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list