R variable not recognized (argument is of length zero)

155 Views Asked by At

I am having an issue with R recognizing a variable.

Background: I am using a tool called DoubletFinder (an R package that predicts doublets in single-cell RNA sequencing data. The RNA data is used to make a Seurat object and as part of the DoubletFinder process, there are some values that are calculated and stored therein within the meta.data slot. The name of the field holding the DoubletFinder data will start with pANN and is followed by a string of characters that will not be known in advance.

I need to automate this so I use grepl to search through the meta.data slot for fields containing the pANN values (line 183, e.g. "pANN_0.25_0.005_0"), assign it to a variable, and use it during the second doubletFinder_v3 call (line 189, reuse.pANN = pann_data).

Code:

183    pann_data = colnames([email protected])[grepl("pANN", colnames([email protected]))]
184    annotations <- [email protected]$seurat_clusters
185    homotypic.prop <- modelHomotypic(annotations)
186    nExp_poi <- round(doublet_rate*nrow([email protected]))
187    nExp_poi.adj <- round(nExp_poi*(1-homotypic.prop))
188    seurat_object <- doubletFinder_v3(seurat_object, PCs = 1:components, pN = pN, pK = pk_value, nExp = nExp_poi, reuse.pANN = FALSE, sct = FALSE)
189    seurat_object <- doubletFinder_v3(seurat_object, PCs = 1:components, pN = pN, pK = pk_value, nExp = nExp_poi.adj, reuse.pANN = pann_data, sct = FALSE)

Error:

Error in if (reuse.pANN != FALSE) { : argument is of length zero
Calls: run_doubletfinder -> doubletFinder_v3
Execution halted

The argument is of length zero which makes me think this is not a DoubletFinder issue per se, the DoubletFinder command is not recognizing the variable. As proof, if I do the following, it works:

189    seurat_object <- doubletFinder_v3(seurat_object, PCs = 1:components, pN = pN, pK = pk_value, nExp = nExp_poi.adj, reuse.pANN = "pANN_0.25_0.005_0", sct = FALSE)

I have tried [email protected][[pann_data]] and [email protected]$pann_data as well.

Does anyone have a work-around that would allow me to keep the process automated? Any advice/suggestions are warmly appreciated with many thanks in advance.

0

There are 0 best solutions below