library(flowWorkspace)
library(openCyto)
library(ggcyto)

fs <- read.ncdfFlowSet("~/Downloads/FlowRepository_FR-FCM-ZZ36_files/pbmc_luca.fcs")
gs <- GatingSet(fs)

FCS_gate1_fun <- function(fr, pp_res = NULL, channels = "FSC-A"){
  peaks_found <- openCyto:::.find_peaks(x = as.numeric(unname(unlist(exprs(fr[, channels])))), num_peaks = 3)
  openCyto::gate_mindensity2(fr, channel = channels, gate_range = sort(peaks_found$x)[1:2])
}
registerPlugins(FCS_gate1_fun, "FCS_gate1")
## [1] TRUE
add_pop(gs, alias = "nonDebris",  pop = "+", parent = "root", dims = "FSC-A", gating_method = "FCS_gate1")
autoplot(gs, "nonDebris")

add_pop(gs, alias = "nonDebris2",  pop = "-", parent = "nonDebris", dims = "FSC-A", gating_method = "mindensity2")
autoplot(gs, "nonDebris2")