R:无法保存对象的元素

时间:2016-07-18 09:30:11

标签: r save

我正在尝试保存一个对象,但它失败了:

+

我可以访问它,我可以使用saveRDS保存它:

> save("MEs", "moduleColors", "net$dendrograms", file = "TNF_AH-network-auto.RData")
Error in save("MEs", "moduleColors", "net$dendrograms", file = "TNF_AH-network-auto.RData") : 
  object ‘net$dendrograms’ not found
> save(list=c("MEs", "moduleColors", "net$dendrograms"), file = "TNF_AH-network-auto.RData")
Error in save(list = c("MEs", "moduleColors", "net$dendrograms"), file = "TNF_AH-network-auto.RData") : 
  object ‘net$dendrograms’ not found
> save(list=c(MEs, moduleColors, net$dendrograms), file = "TNF_AH-network-auto.RData")
Error in FUN(X[[i]], ...) : invalid first argument
> save(MEs, moduleColors, as.vector(net$dendrograms), file = "TNF_AH-network-auto.RData") 
Error in save(MEs, moduleColors, as.vector(net$dendrograms), file = "TNF_AH-network-auto.RData") : 
  object ‘as.vector(net$dendrograms)’ not found
> save(MEs, moduleColors, list(net$dendrograms), file = "TNF_AH-network-auto.RData")
Error in save(MEs, moduleColors, list(net$dendrograms), file = "TNF_AH-network-auto.RData") : 
  object ‘list(net$dendrograms)’ not found
> head(net$dendrograms)
[[1]]

Call:
fastcluster::hclust(d = as.dist(dissTom), method = "average")
...
> ls(net)
 [1] "blockGenes"     "blocks"         "colors"         "dendrograms"   
 [5] "goodGenes"      "goodSamples"    "MEs"            "MEsOK"         
 [9] "TOMFiles"       "unmergedColors"

或者我可以用以下方式保存:

> saveRDS(net$dendrograms, "dendro")
> 

为什么我无法按预期使用> tmp <- list(net$dendrograms) > save(MEs, moduleColors, tmp, file = "TNF_AH-network-auto.RData") > 保存对象?

sessionInfo:

save(MEs, moduleColors, net$dendrograms, file = "TNF_AH-network-auto.RData")

1 个答案:

答案 0 :(得分:0)

我自己也遇到过这个问题。我不知道为什么,但来自save的{​​{1}}命令只能保存&#39;整个&#39;对象。仅保存数据框的一列是不可能的(据我所知)。我的解决方法是:

base