This example doesn't work:
foo <- function(min_val) {
subset(x = pbmc_small, subset = MS4A1 > min_val)
}
foo(4)
Error in eval(expr = expr) : object 'min_val' not found
In WhichCells.Seurat, eval() is being called on an expression, but without capturing the environment that the expression originated at. In the case above, the expression includes a reference to min_val, which exists in the environment that's calling subset.
There are two ways I know of to fix this issue; one is to have WhichCells take an additional envir parameter which defaults to parent.frame(), and also have subset.Seurat take an envir parameter which also defaults to parent.frame(), and have subset.Seurat pass that value to WhichCells.
The other is to use rlang::enquo instead of substitute to capture the expression in subset.Seurat, and use rlang::eval_tidy instead of eval in WhichCells. This should also fix the issue because enquo captures not only the expression AST but also the enclosing environment.
(ref: https://github.com/rstudio/shiny/issues/2801)
Thanks very much for the clear issue report and for providing options to fix
Hi Joe,
Thanks for bringing this up. This should be fixed in the development version of Seurat. To install the development version of Seurat, please see the instructions here.
Hello,
Sorry to come back with it.
I've installed the dev version of Seurat, shiny inputs seem to be reactive now but another error appears:
Warning: Error in : "data" must be uniquely named but has duplicate columns
179: <Anonymous>
This is when Shiny app is internally running this command:
output$viol <- renderPlot({
pbmc2 <- loading_data()
pbmc2 <- subset(pbmc2, subset = nCount_RNA > 500 & nCount_RNA < input$count)
VlnPlot(pbmc2, features = c("nCount_RNA"), ncol = 1)
})
The input$count is finally recognized (I guess) but the error now comes from the subset() function, even by replacing input$count by a real number like this:
pbmc2 <- subset(pbmc2, subset = nCount_RNA > 500 & nCount_RNA < 10000)
It only works when i remove this line, but users won't be able to filter low quality cells.
Do you have an idea about what's causing this ?
Hi Simon,
I'm not entirely sure. Could you provide a copy of the data, a subset of the data, or an example using one of the datasets in SeuratData that reproduces the error, along with a copy of the app so we can debug this further? If you'd rather not post anything to GitHub, you can email us at [email protected]
Hello,
A mail has been sent.
Thank you!
Hi Simon,
That issue should be fixed on the develop branch.
Thanks for bringing this up!