[Rd] Is structure(NA, class = c("def", "condition")) a valid 'condition' object?
Henrik Bengtsson
henr|k@bengt@@on @end|ng |rom gm@||@com
Wed Oct 8 01:42:12 CEST 2025
I think structure(NA, class = c("def", "condition")) is a valid
'condition' object. Am I wrong?
BACKGROUND:
The abstract 'condition' class: why type or mode can a 'condition' object have?
In help("condition"), we can read that:
"Conditions are objects inheriting from the abstract class condition. ..."
and then it specifies the API, i.e. the methods it should support, e.g.
"The functions conditionMessage and conditionCall are generic
functions that return the message and call of a condition."
Then we have several functions for creating 'condition' objects, e.g.
> simpleCondition
function (message, call = NULL)
{
class <- c("simpleCondition", "condition")
structure(list(message = as.character(message), call = call),
class = class)
}
AFAIK, all of them create 'condition' object of type 'list'.
CAN CONDITIONS BE ENVIRONMENTS OR ATOMIC OBJECTS?
However, is the list type a requirement? I cannot find it specified
anywhere. The way I interpret help("condition") and how it is
carefully written using terms like "abstract class" and not mentioning
the type anywhere, I take it as:
cnd1 <- structure(new.env(), class = c("abc", "condition"))
and
cnd2 <- structure(NA, class = c("def", "condition"))
are both valid 'condition' objects, as long as we define the S3
methods for `conditionMessage()` and `conditionCall()`, e.g.
conditionMessage.abc <- function(c) "boom"
conditionCall.abc <- function(c) list()
conditionMessage.def <- function(c) "boom"
conditionCall.def <- function(c) list()
FWIW, I create 'condition' objects of type NA in my 'R.oo' package
going back ~25 years.
Thanks,
Henrik
More information about the R-devel
mailing list