DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

cyto_gate_draw() Error in RStudio notebook #47

Closed rwbaer closed 4 years ago

rwbaer commented 4 years ago

Describe the bug Perhaps this is not a bug and is just an incompatibility issue, in which case it could be considered a feature request. It would be nice to use CytoExploreR in RStudio notebooks as a way to neatly organize copious output.

But ...

Run this in a notebook and it produces an error [the code chunk code is swallowed here]

cyto_gate_draw(gs,
               parent = "root",
               alias = "Cells",
               channels = c("FSC-A", "SSC-A"))

EDIT: As a workaround, I tried putting this code in a separate source file and sourcing it into the notebook. Same behavior. Then, I tried sourcing the cyto_gate_draw function into a regular R script. The graph draws and you can draw the polygate, but the right click to end the drawing sequence does not function. No mechanism to terminate.

The traceback

Error in FUN(X[[i]], ...) : A minimum of 3 points is required to construct a polygon gate.
12.
stop("A minimum of 3 points is required to construct a polygon gate.")
11.
FUN(X[[i]], ...)
10.
lapply(alias, function(alias) { message(paste("Select at least 3 points to construct a polygon gate around the", alias, "population. \n")) options(show.error.messages = FALSE) ...
9.
.cyto_gate_polygon_draw(fr_list[[1]], channels = channels, alias = alias, plot = FALSE, label = label, gate_point_shape = gate_point_shape, gate_point_size = gate_point_size, gate_point_col = gate_point_col, gate_point_col_alpha = gate_point_col_alpha, gate_line_type = gate_line_type, ...
8.
(function (type, alias) { if (type == "polygon") { .cyto_gate_polygon_draw(fr_list[[1]], channels = channels, ...
7.
mapply(function(type, alias) { if (type == "polygon") { .cyto_gate_polygon_draw(fr_list[[1]], channels = channels, alias = alias, plot = FALSE, label = label, gate_point_shape = gate_point_shape, ...
6.
cyto_gate_draw.flowFrame(fr_list[[z]][[1]], alias = unlist(alias), channels = channels, type = type, negate = negate, display = 1, axis = axis, label = label, plot = FALSE, gate_point_shape = gate_point_shape, gate_point_size = gate_point_size, gate_point_col = gate_point_col, ...
5.
cyto_gate_draw(fr_list[[z]][[1]], alias = unlist(alias), channels = channels, type = type, negate = negate, display = 1, axis = axis, label = label, plot = FALSE, gate_point_shape = gate_point_shape, gate_point_size = gate_point_size, gate_point_col = gate_point_col, gate_point_col_alpha = gate_point_col_alpha, ...
4.
FUN(X[[i]], ...)
3.
lapply(seq_along(fr_list), function(z) { if (plot == TRUE) { if (parent == "root") { prnt <- "All Events" ...
2.
cyto_gate_draw.GatingSet(gs, parent = "root", alias = "Cells", channels = c("FSC-A", "SSC-A"))
1.
cyto_gate_draw(gs, parent = "root", alias = "Cells", channels = c("FSC-A", "SSC-A"))

Expected behavior The program should draw graph and pause to collect mouse clicks before moving on. It seems not to in this context.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context

RStudio 1.2.5042

DillonHammill commented 4 years ago

@rwbaer, RStudio notebook and Rmarkdown do not support pop-up graphics devices, and therefore these cannot be using for gating. I did add the option to gate in the RStudio graphics device by setting popup = FALSE in cyto_gate_draw(), you could try that to see if it works. Generally speaking, there is an expectation that rendering documents/notebooks should proceed without user intervention.

I personally tell it not to run cyto_gate_draw() chunks in-line, but instead paste them directly into the console. I then save the image after gating and incorporate that image into the document. Once you have finished gating you can just apply the gatingTemplate and continue with downstream analyses.

rwbaer commented 4 years ago

Sounds like a use-able workaround. Thanks

rwbaer commented 4 years ago

I'll presume you saw my edit about trying to source this plot command into a regular R script. The drawing goes okay, but there is no way to terminate it. Is this a limitation or can it be fixed? I'll not close this yet, so I'm sure you are aware of the edit.

DillonHammill commented 4 years ago

Have you tried pressing ESCAPE?

DillonHammill commented 4 years ago

FYI this should only affect polygon gates, so other gate types will work fine :)