如果加载了ggplot2包,则对对象调用'str'会出错
使用Debian Squence上的如果加载了ggplot2包,则对对象调用'str'会出错,r,debugging,ggplot2,R,Debugging,Ggplot2,使用Debian Squence上的R 2.15.3、ggplot2 0.9.3.1和GTTable 0.1.2对以下内容进行了测试 在调试此ggplot2问题的过程中 ,我遇到了一些我不知道如何调试的东西。我已经在Bitbucket中创建了一个包含相关信息的存储库 该回购协议的相关信息复制如下。 如果你不想使用Mercurial,相关的 包含序列化R数据的文件可以直接从下载 要复制addgrob.asc.save,您可以在gtable的补丁中使用Debian包,或者如果您愿意,也可以在脚本中
R 2.15.3
、ggplot2 0.9.3.1
和GTTable 0.1.2
对以下内容进行了测试
在调试此ggplot2问题的过程中
,我遇到了一些我不知道如何调试的东西。我已经在Bitbucket中创建了一个包含相关信息的存储库
该回购协议的相关信息复制如下。
如果你不想使用Mercurial,相关的
包含序列化R数据的文件可以直接从下载
要复制addgrob.asc.save
,您可以在gtable
的补丁中使用Debian包,或者如果您愿意,也可以在脚本中使用
问题摘要:在对象上运行R的str
函数(这里称为x
)
如果加载了ggplot2
,则会给出错误,否则不会出现错误。我不知道发生了什么事,
因此,任何指点都将不胜感激
###############################################################
要复制此错误,请执行以下操作
从右开始
> 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
traceback()的输出为
附录:在Python中,可以设置一些东西,以便在执行函数时调用的所有代码行都被写入文件中。这可能相当大,但如果在R中可以做到这一点,这将有助于澄清问题。我在谷歌上搜索了一下,但我只找到了各种调试工具
附录2:我已经为此创建了问题。可以更简单地通过以下方法重新创建错误:
x[11]
我认为现在发生的是,您的“x”对象是在一个工作环境中创建的,该工作环境中有“[”个用于“GTTable”对象的方法。您现在将其带回一个一开始没有的工作区,然后在加载ggplot2后,现在有了某种“[”-ggplot2引用的方法,即使未加载gtables
包
我无法通过加载pkg:gtable解决问题。但我不相信“gtable”是一个格式正确的包,因为sessionInfo()
拒绝报告其注册,尽管require(gtable)
报告成功
> require(gtable)
Loading required package: gtable
> `[.gtable`(x, 11)
Error: could not find function "[.gtable"
No suitable frames for recover()
> x[11]
Error in if (any(index < 0)) { : missing value where TRUE/FALSE needed
Enter a frame number, or 0 to exit
1: x[11]
2: `[.gtable`(x, 11)
3: x$heights[rows]
4: `[.unit`(x$heights, rows)
Selection: 0
> sessionInfo()
R version 3.0.0 RC (2013-03-31 r62463)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid grDevices datasets splines graphics utils stats
[8] methods base
other attached packages:
[1] gtable_0.1.2 RCurl_1.95-4.1 bitops_1.0-5
[4] data.table_1.8.8 gplots_2.11.0 MASS_7.3-26
[7] KernSmooth_2.23-10 caTools_1.14 gdata_2.12.0
[10] gtools_2.7.1 ggplot2_0.9.3.1 gridExtra_0.9.1
[13] HH_2.3-36 colorspace_1.2-1 reshape_0.8.4
[16] plyr_1.8 latticeExtra_0.6-24 RColorBrewer_1.0-5
[19] leaps_2.9 multcomp_1.2-17 mvtnorm_0.9-9994
[22] rms_3.6-3 Hmisc_3.10-1 survival_2.37-4
[25] sos_1.3-5 brew_1.0-6 lattice_0.20-15
loaded via a namespace (and not attached):
[1] cluster_1.14.4 dichromat_2.0-0 digest_0.6.3 fortunes_1.5-0
[5] labeling_0.1 munsell_0.4 proto_0.3-10 reshape2_1.2.2
[9] scales_0.2.3 stringr_0.6.2 tools_3.0.0
>需要(gtable)
加载所需包:gtable
>`[.gtable`(x,11)
错误:找不到函数“[.gtable”
没有适合恢复的帧()
>x[11]
if(any(index<0)){中出错:缺少需要TRUE/FALSE的值
输入帧编号,或输入0退出
1:x[11]
2:`[.gtable`(x,11)
3:x$高度[行]
4:`[.unit`(x$高度,行数)
选择:0
>sessionInfo()
R版本3.0.0 RC(2013-03-31 r62463)
平台:x86_64-apple-darwin10.8.0(64位)
区域设置:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
附加基本包:
[1] 网格grDevices数据集样条曲线图形utils统计
[8] 方法库
其他随附包裹:
[1] GTTable_0.1.2 RCurl_1.95-4.1比特运算_1.0-5
[4] 数据表1.8.8 GPU 2.11.0质量表7.3-26
[7] KernSmooth_2.23-10 caTools_1.14 gdata_2.12.0
[10] gtools_2.7.1 ggplot2_0.9.3.1 gridExtra_0.9.1
[13] HH_2.3-36色彩空间_1.2-1重塑_0.8.4
[16] plyr_1.8格子额外_0.6-24 RColorBrewer_1.0-5
[19] 跳跃2.9 multcomp 1.2-17 mvtnorm 0.9-9994
[22]rms_3.6-3 Hmisc_3.10-1生存率_2.37-4
[25]sos_1.3-5 brew_1.0-6 lattice_0.20-15
通过命名空间加载(未附加):
[1] 集群1.14.4重铬酸盐2.0-0摘要0.6.3财富1.5-0
[5] 标记0.1蒙塞尔0.4原型0.3-10重塑2 1.2.2
[9] 比例尺\u 0.2.3纵梁\u 0.6.2工具\u 3.0.0
(我确实安装了GTTable 0.1.2。)
附录:可使用此代码复制:
test <- data.frame(x=1:20, y=21:40,
facet.a=rep(c(1,2), 10),
facet.b=rep(c(1,2), each=20))
p <- qplot(data=test, x=x, y=y, facets=facet.b~facet.a)
# get gtable object
z <- ggplot_gtable(ggplot_build(p))
length(z)
#[1] 16
z[16] # drops into browser
test可以更简单地通过以下方法重新创建错误:
x[11]
我认为现在发生的是,您的“x”对象是在一个工作环境中创建的,该工作环境中有“[”个用于“GTTable”对象的方法。您现在将其带回一个一开始没有的工作区,然后在加载ggplot2后,现在有了某种“[”-ggplot2引用的方法,即使未加载gtables
包
我无法通过加载pkg:gtable解决问题。但我不相信“gtable”是一个格式正确的包,因为sessionInfo()
拒绝报告其注册,尽管require(gtable)
报告成功
> require(gtable)
Loading required package: gtable
> `[.gtable`(x, 11)
Error: could not find function "[.gtable"
No suitable frames for recover()
> x[11]
Error in if (any(index < 0)) { : missing value where TRUE/FALSE needed
Enter a frame number, or 0 to exit
1: x[11]
2: `[.gtable`(x, 11)
3: x$heights[rows]
4: `[.unit`(x$heights, rows)
Selection: 0
> sessionInfo()
R version 3.0.0 RC (2013-03-31 r62463)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid grDevices datasets splines graphics utils stats
[8] methods base
other attached packages:
[1] gtable_0.1.2 RCurl_1.95-4.1 bitops_1.0-5
[4] data.table_1.8.8 gplots_2.11.0 MASS_7.3-26
[7] KernSmooth_2.23-10 caTools_1.14 gdata_2.12.0
[10] gtools_2.7.1 ggplot2_0.9.3.1 gridExtra_0.9.1
[13] HH_2.3-36 colorspace_1.2-1 reshape_0.8.4
[16] plyr_1.8 latticeExtra_0.6-24 RColorBrewer_1.0-5
[19] leaps_2.9 multcomp_1.2-17 mvtnorm_0.9-9994
[22] rms_3.6-3 Hmisc_3.10-1 survival_2.37-4
[25] sos_1.3-5 brew_1.0-6 lattice_0.20-15
loaded via a namespace (and not attached):
[1] cluster_1.14.4 dichromat_2.0-0 digest_0.6.3 fortunes_1.5-0
[5] labeling_0.1 munsell_0.4 proto_0.3-10 reshape2_1.2.2
[9] scales_0.2.3 stringr_0.6.2 tools_3.0.0
>需要(gtable)
加载所需包:gtable
>`[.gtable`(x,11)
错误:找不到函数“[.gtable”
没有适合恢复的帧()
>x[11]
if(any(index<0)){中出错:缺少需要TRUE/FALSE的值
输入帧编号,或输入0退出
1:x[11]
2:`[.gtable`(x,11)
3:x$高度[行]
4:`[.unit`(x$高度,行数)
选择:0
>sessionInfo()
R版本3.0.0 RC(2013-03-31 r62463)
平台:x86_64-apple-darwin10.8.0(64位)
区域设置:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
附加基本包:
[1] 网格grDevices数据集样条曲线图形utils统计
[8] 方法库
其他随附包裹:
[1] GTTable_0.1.2 RCurl_1.95-4.1比特运算_1.0-5
[4] 数据表1.8.8 GPU 2.11.0质量表7.3-26
[7] KernSmooth_2.23-10 caTools_1.14 gdata_2.12.0
[10] gtools_2.7.1 ggplot2_0.9.3.1 gridExtra_0.9.1
[13] HH_2.3-36色彩空间_1.2-1重塑_0.8.4
[16] plyr_1.8格子额外_0.6-24 RColorBrewer_1.0-5
[19] 跳跃2.9 multcomp 1.2-17 mvtnorm 0.9-9994
[22]rms_3.6-3 Hmisc_3.10-1生存率_2.37-4
[25]sos_1.3-5 brew_1.0-6 lattice_0.20-15
通过命名空间加载(未附加):
[1] 集群1.14.4重铬酸盐2.0-0摘要0.6.3财富1.5-0
[5] 标记0.1蒙塞尔0.4原型0.3-10重塑2 1.2.2
[9] 比例尺\u 0.2.3纵梁\u 0.6.2工具\u 3.0.0
(我有GTTable 0.1.2安装版
str.gtable <- function(object, ...){
cat(c("gtable, containing \ngrobs (",
length(object[["grobs"]]), "), with names :"), sep="")
utils::str(names(object[["grobs"]]))
cat("layout :\n")
utils::str(object[["layout"]])
cat("widths :\nunit vector of length",
length(object[["widths"]]), "\n")
cat("heights :\nunit vector of length",
length(object[["heights"]]), "\n")
for(element in c("respect", "rownames",
"name", "gp", "vp")){
cat(element, ":\n")
utils::str(object[[element]])
}
}
library(gridExtra)
g <- tableGrob(head(iris))
str(g)
gtable, containing
grobs (84), with names : chr [1:84] "" "" "" "" "" "" "" "" "" "" "" "" ...
layout :
'data.frame': 84 obs. of 7 variables:
$ t : int 1 2 3 4 5 6 7 1 2 3 ...
$ l : int 1 1 1 1 1 1 1 1 1 1 ...
$ b : int 1 2 3 4 5 6 7 1 2 3 ...
$ r : int 1 1 1 1 1 1 1 1 1 1 ...
$ z : num 1 2 3 4 5 6 7 0 0 0 ...
$ clip: chr "on" "on" "on" "on" ...
$ name: chr "rowhead-fg" "rowhead-fg" "rowhead-fg" "rowhead-fg" ...
widths :
unit vector of length 6
heights :
unit vector of length 7
respect :
logi FALSE
rownames :
NULL
name :
chr "rowhead-fg"
gp :
NULL
vp :
NULL