Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: How come that "is" is TRUE, but "as" is impossible?

Tags:

r

The class "ecdf" inherits from the class "stepfun". If f is such an empirical cumulative density function, both is.stepfun(f) and is(f,"stepfun") are TRUE, and as.stepfun(f) doesn't do anything as expected. But conversion of f to "stepfun" by as(f,"stepfun") is impossible because of the "metadata", even if strict is FALSE:

f <- ecdf(1:10)

class(f)
# [1] "ecdf"     "stepfun"  "function"

is.stepfun(f)
# [1] TRUE

is(f,"stepfun")
# [1] TRUE

identical(f,as.stepfun(f))
# [1] TRUE

g <- as(f,"stepfun",strict=FALSE)
# Error in as(f, "stepfun", strict = FALSE) : 
#   internal problem in as(): “ecdf” is(object, "stepfun") is TRUE, but the metadata asserts that the 'is' relation is FALSE

So how is is related to as and what is the meaning of the "metadata" here?

like image 489
mra68 Avatar asked Oct 31 '22 10:10

mra68


1 Answers

I may have found some relevant information. At this nabble archive

but it has two problems: 

1) as() is an S4 method that does not always work 
(problem 2 not relevant)

Locally :-) this SO question has warnings about trying to use as()

So my suggestion would be to stick with as.stepfun(foo) .

like image 80
Carl Witthoft Avatar answered Nov 15 '22 05:11

Carl Witthoft