The following was tested with R 2.15.3, ggplot2 0.9.3.1 and gtable 0.1.2 on Debian squeeze.
In the course of debugging this ggplot2 issue multiple calls to annotation_custom fail in certain cases, I came across something I don't know how to debug. I've created a repository in Bitbucket with the relevant information github-ggplot2-817.
The relevant README from that repos is copied below. If you don't want to use Mercurial, the relevant file with serialized R data can be downloaded directly from addgrob.asc.save.
To reproduce addgrob.asc.save, you could use the Debian packaging in https://bitbucket.org/faheem/gtable-debian, or if you prefer, just the patch to gtable, namely gtableaddgrob.diff, along with the script save.R.
Summary of the issue: running R's str function on an object (here called x)
gives an error if ggplot2 is loaded, but not otherwise. I'm not sure what is going on,
so any pointers would be appreciated.
###############################################################
To reproduce this bug, do the following.
Start R. Then
> ls()
character(0)
> load("addgrob.asc.save")
> ls()
[1] "grobs" "layout" "x"
> str(x, max.level=1)
List of 10
$ grobs :List of 8
$ layout :'data.frame': 8 obs. of 7 variables:
$ widths :Class 'unit' atomic [1:6] 1.5 6.096 0.762 1.961 0 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ heights :Class 'unit' atomic [1:7] 1.5 2.53 1.52 6.1 6.1 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ respect : logi FALSE
$ rownames: NULL
$ colnames: NULL
$ name : chr "layout"
$ gp : NULL
$ vp : NULL
- attr(*, "class")= chr [1:3] "gtable" "grob" "gDesc"
## Now update x
> x$grobs <- c(x$grobs, grobs)
> x$layout <- rbind(x$layout, layout)
> str(x, max.level=1)
List of 10
$ grobs :List of 11
$ layout :'data.frame': 11 obs. of 7 variables:
$ widths :Class 'unit' atomic [1:6] 1.5 6.096 0.762 1.961 0 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ heights :Class 'unit' atomic [1:7] 1.5 2.53 1.52 6.1 6.1 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ respect : logi FALSE
$ rownames: NULL
$ colnames: NULL
$ name : chr "layout"
$ gp : NULL
$ vp : NULL
- attr(*, "class")= chr [1:3] "gtable" "grob" "gDesc"
> library(ggplot2)
> str(x, max.level=1)
List of 11
$ grobs :List of 11
$ layout :'data.frame': 11 obs. of 7 variables:
$ widths :Class 'unit' atomic [1:6] 1.5 6.096 0.762 1.961 0 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ heights :Class 'unit' atomic [1:7] 1.5 2.53 1.52 6.1 6.1 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ respect : logi FALSE
$ rownames: NULL
$ colnames: NULL
$ name : chr "layout"
$ gp : NULL
$ vp : NULL
$ NA:Error in object[[i]] : subscript out of bounds
Loading ggplot2 does not cause the earlier version of x to error
out str.
> ls()
character(0)
> load("addgrob.asc.save")
l> ls()
[1] "grobs" "layout" "x"
> library(ggplot2)
> str(x, max.level=1)
List of 8
$ grobs :List of 8
$ layout :'data.frame': 8 obs. of 7 variables:
$ widths :Class 'unit' atomic [1:6] 1.5 6.096 0.762 1.961 0 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ heights :Class 'unit' atomic [1:7] 1.5 2.53 1.52 6.1 6.1 ...
.. ..- attr(*, "unit")= chr "mm"
.. ..- attr(*, "valid.unit")= int 7
$ respect : logi FALSE
$ rownames: NULL
$ colnames: NULL
$ name : chr "layout"
- attr(*, "class")= chr [1:3] "gtable" "grob" "gDesc"
The output of traceback() is
> traceback()
2: str.default(x, max.level = 1)
1: str(x, max.level = 1)
ADDENDUM: In Python it is possible to set things up so that all lines of code called when a function is executed are written to a file.This can be rather voluminous, but if this was possible in R, it would help to clarify things. I did a Google search, but all I came up with were various debugging utilities.
ADDENDUM2: I've created the issue The str function fails with error on ggplot2 objects for this.