Skip to content

as.ggplot() causes Error in UseMethod("ggplot_build") #114

@jttoivon

Description

@jttoivon

This bug is a continuation of bug 113.

In the following example the call to as.ggplot() gives an error. Or rather, when
the result of as.ggplot(p2) gets evaluated by ggcyto:::print.ggcyto(), the implementation calls as.ggplot()
again, which then later results into error. The problems seems to be that as.ggplot() isn't idempotent, as
the result changes, if it is called multiple times.

library(ggcyto)
#> Loading required package: ggplot2
#> Loading required package: flowCore
#> Loading required package: ncdfFlow
#> Loading required package: BH
#> Loading required package: flowWorkspace
#> As part of improvements to flowWorkspace, some behavior of
#> GatingSet objects has changed. For details, please read the section
#> titled "The cytoframe and cytoset classes" in the package vignette:
#> 
#>   vignette("flowWorkspace-Introduction", "flowWorkspace")
data(GvHD)
flow_set <- GvHD[1:3]
gating_set <- GatingSet(flow_set)
p2 <- ggcyto(gating_set, subset="root", aes(x = "FSC-H", y = "SSC-H")) + geom_hex()
p2

p2 |> class()
#> [1] "ggcyto_GatingSet" "ggcyto_flowSet"   "ggcyto"           "ggplot2::ggplot" 
#> [5] "ggplot"           "ggplot2::gg"      "S7_object"        "gg"
p2 |> as.ggplot() |> class()
#> [1] "ggcyto"          "ggplot2::ggplot" "ggplot"          "ggplot2::gg"    
#> [5] "S7_object"       "gg"
p2 |> as.ggplot() |> as.ggplot() |> class()
#> [1] "ggplot"      "ggplot2::gg" "S7_object"   "gg"
as.ggplot(p2)
#> Error in `UseMethod()`:
#> ! no applicable method for 'ggplot_build' applied to an object of class "c('ggplot', 'ggplot2::gg', 'S7_object', 'gg')"

Created on 2026-05-20 with reprex v2.1.1

I'm running R version 4.6.0.

packageVersion("ggplot2")
#> [1] '4.0.3'
packageVersion("ggcyto")
#> [1] '1.39.4'

Created on 2026-05-19 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions