【发布时间】:2021-03-02 01:09:50
【问题描述】:
我正在尝试将 ggplot 对象保存在 S4 插槽中。
考虑:
library(stats4)
library(ggplot2)
setClass("gginS4",
contains = c("ggplot"),
slots = c(
p = "ggplot"))
允许通过gginS4@p 访问 ggplot。我已经将这种方法用于其他类型的数据(即“sf”等),没有问题。但是,上面的示例会产生以下错误:
Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, :
no definition was found for superclass “ggplot” in the specification of class “gginS4”
使用ggplot2::ggplot() 创建的对象有两个类gg 和ggplot,但setClass() 找不到这两个超类的定义。是否有另一种方法来定义插槽?
【问题讨论】: