R error : "attempt to select less than one element in get1index" - 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 ?

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

Related

httr2 `req_proxy` Error in constants[[]] : subscript out of bounds

I have opened an issue with the package developers,Bug Report, it seems there is a bug in httr2::req_proxy that can be found from the document reprex. It seems as though the logic error is coming from httr2::auth_flags() and is trying to select an unavailable matrix position from the list of authentiation options it makes available? Does anyone have any clue as to why the code would be written this way OR any idea on how to refactor to not lose any function but correct the error?
REPREX + Error:
httr2::request("http://hadley.nz") %>%
httr2::req_proxy("20.116.130.70", 3128) %>%
httr2::req_perform()
# Error in constants[[]] : subscript out of bounds
auth_flags() LOGIC:
auth_flags <- function (x = "basic")
{
constants <- c(basic = 1, digest = 2, gssnegotiate = 4,
ntlm = 8, digest_ie = 16, any = -17)
idx <- arg_match0(x, names(constants), arg_nm = "auth",
error_call = caller_env())
constants[[]] # Why is this here?
}

R: Parallel Processing Error: "Errorr in checkForRemoteErrors(val) : 5 nodes produced errors; first error: Objekt 'RAD' not found"

I am currently conducting an CRQA on heart rate and respiration data. I try to parallelize the computation in the following way, because I want to run them on an external server:
RAD = round(median(Param_list$radius), digits = 2); RAD # defining the final parameter settings
DEL = max(Param_list$delay); DEL
EMB = max(Param_list$emddim); EMB
my_crqa = function(x, y){
crqa::crqa(x, y,
radius = RAD, embed = EMB, delay = DEL,
rescale = 2, normalize = 2,
mindiagline = 25, minvertline = 25, tw = 0, whiteline = FALSE,
side = "both", method = "crqa",
metric = "euclidean", datatype = "continuous")
}
memory.size(max = TRUE)
core = round(detectCores()*0.8, digits = 0)
cl<-makeCluster(core, type="SOCK")
clusterEvalQ(cl, c("my_crqa", "EMB", "DEL", "RAD"))
CRQA_list = clusterMap(cl, my_crqa, HR_clean, HR_clean)
stopCluster(cl) # Stop cores properly.
Unfortunately, I get the following error:
"Errorr in checkForRemoteErrors(val) : 5 nodes produced errors;
first error: Objekt 'RAD' not found"
Why does the cluster not find the RAD, but the the other variables? Also, when I ran the code earlier it worked.
I appreciate any tip!
Best,
Johnson

Clustering by M3C package : Error in `[.data.frame`(df, neworder2) : undefined columns selected

I had a similar problem to what posted here. To resolve the issue, followed the answer by #Jack Gisby there. Now a new error showed up:
Working on TCGA data , I am getting the same error (first error):
Error in `.rowNamesDF<-`(x, value = value) :
duplicate 'row.names' are not allowed
running duplicated() on each relevant field returned FALSE.
Her is the second error (just after trimming identifiers to not start with a common string like "TCGA-"):
Error in `[.data.frame`(df, neworder2) : undefined columns selected
> traceback()
5: stop("undefined columns selected")
4: `[.data.frame`(df, neworder2)
3: df[neworder2]
2: M3Creal(as.matrix(mydata), maxK = maxK, reps = repsreal, pItem = pItem,
pFeature = 1, clusterAlg = clusteralg, distance = distance,
title = "/home/christopher/Desktop/", des = des, lthick = lthick,
dotsize = dotsize, x1 = pacx1, x2 = pacx2, seed = seed, removeplots = removeplots,
silent = silent, fsize = fsize, method = method, objective = objective)
1: M3C(pro.vst, des = clin, removeplots = FALSE, iters = 25, objective = "PAC",
fsize = 8, lthick = 1, dotsize = 1.25)
I've added to an opened issue on the M3C GitHub.
I got the same error as Hamid Ghaedi while running M3C. I managed to track it down to the following line of code (line 476 on the M3C.R file):
df <- data.frame(m_matrix)
Many of my sample names (column names) started with a number and the data.frame() function added an "X" to the beginning of each name that started with a number ("1" becomes "X1"). This caused a mismatch with the names listed in neworder2.
To get around this problem, I changed all of my sample names to start with a letter and M3C is now running correctly.
Edit: This workaround can be easily applied by using the data.frame() function on your input dataset before running M3C.

arulesViz subscript out of bounds paracoord

I want to perform basket analysis and draw a paracoord plot however I receive an error.
Content of this error is: :
Error in m[j, i] : subscript out of bounds.In addition: Warning message:
In cbind(pl, pr) :
number of rows of result is not a multiple of vector length (arg 2)
I am using data from: Link.
First I am transforming this to fit basket analysis, name of the original excel files is Online_Retail:
library(arules)
library(arulesViz)
library(plyr)
items <- ddply(Online_Retail, c("CustomerID", "InvoiceDate"), function(df1)paste(df1$Description, collapse = ","))
items1 <- items["V1"]
write.csv(items1, "groceries1.csv", quote=FALSE, row.names = FALSE, col.names = FALSE)
trans1 <- read.transactions("groceries1.csv", format = "basket", sep=",",skip=1)
And to draw paracoord I have created such a code:
rules.trans2<-apriori(data=trans1, parameter=list(supp=0.001,conf = 0.05),
appearance=list(default="rhs", lhs="ROSES REGENCY TEACUP AND SAUCER"), control=list(verbose=F))
sorted.plot <- sort(rules.trans2, by="support", decreasing = TRUE)
plot(sorted.plot, method="paracoord", control=list(reorder=TRUE, verbose = TRUE))
Why my code for paracoord is not working? how can I fix it? What should I change?
This is, unfortunately, a bug in arulesViz. This will be fixed in the next release (arulesViz 1.3-3). The fix is already available in the development version on GitHub: https://github.com/mhahsler/arulesViz

Trouble with running h2o.hit_ratio_table

I got this issue when I run H2o for xgboost. May I ask how can I solve this issue? Thank you.
I run this code
h2o.hit_ratio_table(gbm2,valid =T)
And I encounter this error
" Error in names(v) <- v_names :
'names' attribute [1] must be the same length as the vector [0]"
Then I proceed run
mean(finalRF_prediction$predict==test_gb$Cover_Type)
and I got the error:
Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page, :
ERROR MESSAGE:
Name lookup of 'NULL' failed
My model is:
gbm2=h2o.gbm(training_frame = train_gb,validation_frame = valid_gb,x=1:51,y=52,
model_id="gbm2_covType_v2",
ntrees=200,
max_depth = 30,
sample_rate = .7,
col_sample_rate = .7,
learn_rate=.3,
stopping_round=2,
stopping_tolerance = .01,
score_each_iteration = T,seed=2000000)
finalRF_prediction=h2o.predict(object=gbm2,newdata = test_gb)
summary(gbm2)
h2o.hit_ratio_table(gbm2,valid=T)[1,2]
mean(finalRF_prediction$predict==test_gb$Cover_Type)
Without having a dataset to rerun your code on it's hard to say what caused the error. For your second error, check if the column Cover_Type exists in your test_gb dataframe.
The code you have seems to be fine, so I would just double check your column names.
In addition here is a code snippet with xgboost that shows you, you can use the hit_ratio_table() successfully.
library(h2o)
h2o.init()
iris.hex <- h2o.importFile( "http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv")
i.sid <- h2o.runif(iris.hex)
iris.train <- h2o.assign(iris.hex[i.sid > .2, ], "iris.train")
iris.test <- h2o.assign(iris.hex[i.sid <= .2, ], "iris.test")
iris.xgboost.valid <- h2o.xgboost(x = 1:4, y = 5, training_frame = iris.train, validation_frame = iris.test)
# Hit ratio
hrt.valid.T <- h2o.hit_ratio_table(iris.xgboost.valid,valid = TRUE)
print(hrt.valid.T)

Resources