R错误:“尝试在get1index中选择少于一个元素”

时间:2017-07-06 13:11:01

标签: r

我是R的初学者,我正在尝试使用 ClonEvol 软件包,但github网页上的文档非常有限。所以现在我正在使用他们的示例代码并尝试将其调整为我的数据 ce

  ce <- data.frame(
  cluster = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7),
  gene = c("geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC",
 "geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD"),
  prim.vaf = c(0.5,0,0,0,0.5,0.5,0,0,1,0.5,0,0,1,0.5,0,0.5,0.5,0.5,0,0.5,0.5,0.5,0,1,0.5,0.5,0.5,0)
        )

    cluster <- ce$cluster
    gene <- ce$gene
    prim.vaf <- ce$prim.vaf

    x <- ce

    vaf.col.names <- grep('prim.vaf', colnames(x), value=T)
    sample.names <- gsub('prim.vaf', '', vaf.col.names)
    x[, sample.names] <- x[, vaf.col.names]
    vaf.col.names <- sample.names
    sample.groups <- c('P', 'R');
    names(sample.groups) <- vaf.col.names
    x <- x[order(x$cluster),]

    pdf('box.pdf', width = 3, height = 5, useDingbats = FALSE, title='')
    pp <- variant.box.plot(x,
   cluster.col.name = ce$cluster,
   show.cluster.size = FALSE,
   cluster.size.text.color = 'blue',
   vaf.col.names = vaf.col.names,
   vaf.limits = 70,
   sample.title.size = 20,
   violin = FALSE,
   box = FALSE,
   jitter = TRUE,
   jitter.shape = 1,
   jitter.color = clone.colors,
   jitter.size = 3,
   jitter.alpha = 1,
   jitter.center.method = 'median',
   jitter.center.size = 1,
   jitter.center.color = 'darkgray',
   jitter.center.display.value = 'none',
   highlight = 'is.driver',
   highlight.note.col.name = 'gene',
   highlight.note.size = 2,
   highlight.shape =16,
   order.by.total.vaf = FALSE
    )
    dev.off()

但是,我收到以下错误:

    Error in .subset2(x, i, exact = exact) : recursive indexing failed at level 2

如果我删除 cluster.col.name = ce $ cluster vaf.col.names = vaf.col.names ,则错误将变为:< / p>

    Error in .subset2(x, i, exact = exact) : attempt to select less than one     
    element in get1index

有人知道出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

我今天遇到了此错误消息。对于这个问题,我对R软件包知之甚少,但是我想在这里可以显示错误消息的含义。也许对您找出问题很有用。

当我们使用NULL作为索引对列表进行子集化时,会发生错误。
以下是调用此错误消息的表达式:

any.list <- list(1, 2, 3)
# If single brackets, no error occurs: 
any.list[NULL]
## list()

# If double brackets, the error occurs: 
any.list[[NULL]]
## Error in any.list[[NULL]] : 
##   attempt to select less than one element in get1index

上面的list可以是任何列表,甚至可以是向量。

a.vector <- c(1, 2, 3)
a.vector[[NULL]]
## Error in a.vector[[NULL]] : 
##   attempt to select less than one element in get1index

这是类似的错误消息:

any.list[[0]]
## Error in any.list[[0]] : 
##   attempt to select less than one element in get1index <real>

END