Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R error : "attempt to select less than one element in get1index"

Tags:

r

I'm a beginner in R and I'm trying to use the package ClonEvol, however the documentation on the github webpage is very limited. So for now I'm using their example code and trying to adapt it to my data called 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()

However, I get the following error :

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

And if I delete cluster.col.name=ce$cluster and vaf.col.names=vaf.col.names, the error becomes the following :

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

Has someone any idea of what went wrong ?

like image 897
Tso Avatar asked Jul 06 '17 13:07

Tso


People also ask

Why does RStudio return “attempt to select less than one element in get1index real”?

As you can see, the RStudio console has returned the error “attempt to select less than one element in get1index real” after executing the previous syntax. The reason for this is that we have tried to select the 0th element of our list, i.e. a list element that does not exist. In our example this mistake might be obvious.

What is [null] error in get1index?

The error occurs when we use NULL as an index to subset a list. 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

Why is my list element number less than one?

This error message occurs when you try to access a list element number that is less than one. Fixing the problem involves making sure the list element number is one or greater. While this can happen even if you are not using a package function, it can easily happen when making a plot using an r package.

How do I fix a list element number problem in R?

Fixing the problem involves making sure the list element number is one or greater. While this can happen even if you are not using a package function, it can easily happen when making a plot using an r package. A list is similar to a data frame in that it consists of multiple elements.


1 Answers

I met this error message today. I know little about the R package in this question, but I think I can show what the error message means here. And maybe it is useful for you to find out the problem.

The error occurs when we use NULL as an index to subset a list.
Here are the expressions invoking this error message:

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

The list above can be any list, or even a vector.

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

Here is a similar error message:

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

END

like image 172
D. Chern Liang Avatar answered Nov 03 '22 00:11

D. Chern Liang