我收到消息
parent.frame() 中的错误:节点堆栈溢出 总结期间的错误:节点堆栈溢出
当我尝试使用 S4 命令“as”构造对象时,但仅当超类被声明为“VIRTUAL”时。
类层次结构如下:
PivotBasic 包含 Pivot 包含模型
Pivot 和 Pivot Basic 的 setClass 命令以及 PivotBasic 的构造函数如下所示。类 Pivot 没有构造函数。Model 构造函数太大,无法在此处插入。
这真的没什么大不了的(我认为),因为如果从 setClass 的表示参数中删除“VIRTUAL”关键字,一切都会正常工作。但我很好奇问题的原因。有人对此有见解吗?
谢谢,
费尔南多·萨尔达尼亚
setClass(Class = "Pivot",
representation = representation(
pivotName = "character",
pivotNames = "character",
pivotData = "data.frame",
"VIRTUAL"
),
contains = "Model"
)
setClass(Class = "PivotBasic",
representation = representation(),
contains = "Pivot"
)
pivotBasic <- function(
portfolio,
assets,
controlVariableList,
pivotData = NULL, # pivotName is ignored if pivotData is not null
pivotName = "N_WEEKDAY_3_6",
firstPredictionDate = as.Date(integer(), origin = "1970-01-01"),
name = NULL,
tags = "Event"
) {
if (missing(portfolio)) stop("[PivotBasic: pivotBasic] - Missing portfolio argument")
if (missing(assets)) stop("[PivotBasic: pivotBasic] - Missing assets argument")
if (missing(controlVariableList)) stop("[PivotBasic: pivotBasic] - Missing controlVariableList argument")
object <- model(
portfolio,
assets,
controlVariableList,
firstPredictionDate,
name,
tags)
# The error message happens when this command is executed
mdl <- as(object, "PivotBasic")
# Other code
mdl
} # end pivotBasic