> showDefault
function (object, oldMethods = TRUE)
{
clDef <- getClass(cl <- class(object), .Force = TRUE)
cl <- classLabel(cl)
if (!is.null(clDef) && isS4(object) && is.na(match(clDef@className,
.BasicClasses))) {
cat("An object of class ", cl, "\n", sep = "")
slots <- slotNames(clDef)
dataSlot <- .dataSlot(slots)
if (length(dataSlot) > 0) {
dataPart <- slot(object, dataSlot)
show(dataPart)
slots <- slots[is.na(match(slots, dataSlot))]
}
else if (length(slots) == 0L)
show(unclass(object))
for (what in slots) {
if (identical(what, ".Data"))
next
cat("Slot \"", what, "\":\n", sep = "")
print(slot(object, what))
cat("\n")
}
}
else print(object, useS4 = FALSE)
invisible()
}
<bytecode: 0x11c228000>
<environment: namespace:methods>
Substitute From Implicit `show` Call
-
22-09-2022 - |
문제
I need to recover the expression implicitly used to invoke a call to show
from within a show
method, but this only works with an explicit show call:
> setClass("test", representation(a="character"))
> setMethod("show", "test", function(object) cat(deparse(substitute(object))))
[1] "show"
> show(new("test")) # explicit call: as expected
new("test")
> new("test") # implicit: not so much...
<S4 object of class structure("test", package = ".GlobalEnv")>
There seems to be a similar issue with print and S3 objects, but I'm more interested in the S4 version here. Any way to work around this? I looked at the call stack with sys.calls
but there was no call recorded with the original expression which suggests to me this may be too low level to be resolved easily.
올바른 솔루션이 없습니다
다른 팁
제휴하지 않습니다 StackOverflow