On 6/9/2009 9:02 AM, baptiste auguie wrote:> Dear list,
>
> I'm quite surprised by this,
>
> unit(1:5,"char")[-c(1:2)]
> #4char 3char # what's going on??
>
> while I expected something like,
>
>
> c(1:5)[-c(1:2)]
>
> # 3 4 5
>
> Note that,
>
> unit(1:5,"char")[c(1:2)]
>
> # 1char 2char # fine
>
> ?unit warns about unit.c for concatenating, but also says,
>
> It is possible to subset unit objects in the normal way (e.g.,
unit(1:5,"npc")[2:4])
>
> Am I missing something obvious?
No, I think the grid:::unit.[ method has a bug. It does the indexing of
an object x by making sure the indices are integers, then
class(x) <- NULL
x <- x[(index - 1)%%this.length + 1]
which assumes that index has positive entries.
Duncan Murdoch
>
> Thanks,
>
> baptiste
>
> sessionInfo()
> R version 2.9.0 (2009-04-17)
> i386-apple-darwin8.11.1
>
> locale:
> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] datasets stats grid graphics grDevices utils methods
base
>
> ______________________________________________
> 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.