gpt4 book ai didi

r - 防止 print() 在 R 中输出列表索引

转载 作者:行者123 更新时间:2023-12-04 19:20:29 24 4
gpt4 key购买 nike

我有一个 list包含六个图,如下所示:

voi=c('inadist','smldist','lardist')

plist <- llply(voi,
function(v,df,s) {
list(
assign(
paste(v,'.violin'),
bwplot(groupname~df[,which(colnames(df)==v)]|fCycle*fPhase,
data=df,
groups=groupname, col=rainbow(1), box.ratio=3,
main=paste('Distribution of ', v, ' by Treatment and Cycle'),
sub=s, xlab=v, panel=panel.violin)),
assign(
paste(v,'.hexbin'),
hexbinplot(df[,which(colnames(df)==v)]~starttime|groupname,
data=df, xlab='Time(s)',main= paste('Distribution of ',v,' by Treatment'),
sub=s,ylab=v, aspect=0.5, colramp=redgrad.pal, layout=c(2,4)))

)
},data,meta$exp_name)

如果我打印列表, print(plist) ,绘图输出到图形设备,然后索引输出到控制台,结果如下:
[[1]]
[[1]][[1]]

[[1]][[2]]


[[2]]
[[2]][[1]]

[[2]][[2]]


[[3]]
[[3]][[1]]

[[3]][[2]]

因为我正在编写一个 web 应用程序,所以我需要非常严格地控制控制台输出。到目前为止,我可以在不输出索引的情况下输出图的唯一方法是这样的:
for(p in plist) 
for(i in p)
print(i)

有没有更有效的方式来获得我需要的东西?

最佳答案

你可以用 capture.output 作弊:

dummy <- capture.output(print(plist))

或不创建新变量
invisible(capture.output(print(plist)))

顺便说一下,可重现的示例如下所示:
require(lattice)
plist <- list(
list(bwplot(rnorm(10)),bwplot(rnorm(10))),
list(bwplot(rnorm(10)),bwplot(rnorm(10))),
list(bwplot(rnorm(10)),bwplot(rnorm(10)))
)

关于r - 防止 print() 在 R 中输出列表索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3968693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com