Hi,
I am using the subset function from Seurat to filter the genes present in the Seurat object as follows:
sample <- subset(sample, features = keep)
This works fine in RStudio, however when I run several samples in a loop using the rmarkdown::render()
command, my code crashes on the second sample (the first sample runs completely fine) with the error:
Error in data[data_types == l, , drop = FALSE] :
object of type 'S4' is not subsettable
Calls: <Anonymous> ... withVisible -> eval -> eval -> Read10X -> lapply -> FUN
I presume it is trying to use the wrong subset
function, but I am not sure why and I am also struggling to work out how to explicitly call the Seurat subset function.
I tried SeuratObject::subset()
but it says the subset is not exported from the SeuratObject package. I have saved the sample
object and it is definitely a Seurat object.
Any help would be greatly appreciated.
Best wishes,
Lucy
With the given information this is barely reproducible. Try to put together a minimal working example incl all relevant code especially the rendering command and how you load packages. It can be that you are loading from an environment in RStudio that is not accessable to the rendering command.
Don't use
sample
as a variable name in R, as there is asample
function in R. showing yourkeep
andsample
will be helpful.Thank you - I think I might have fixed the issue by wrapping
Rmarkdown::render
insideRscript_call()