5

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?

mra68
  • 2,960
  • 1
  • 10
  • 17
  • did you mean `is.stepfun(f)` right after `class(f)` ? – Carl Witthoft Jan 27 '16 at 16:11
  • I'm interested - where did you dig up the format `is(item,typedef)` as opposed to the format in all the help pages `is.typedef(item)` ? You also might want to try `methods(as)` and a couple similar investigations to see what's going on with the `stepfun` class in particular. – Carl Witthoft Jan 27 '16 at 16:29
  • 1
    @Carl Witthoft: Searching for "R coercing" leads to the [documentation for the `as` method](https://stat.ethz.ch/R-manual/R-devel/library/methods/html/as.html). Therein is a link ([setIs](https://stat.ethz.ch/R-manual/R-devel/library/methods/html/is.html)) to the [documentation for the `is` method](https://stat.ethz.ch/R-manual/R-devel/library/methods/html/is.html). – mra68 Jan 27 '16 at 21:44

1 Answers1

2

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) .

Community
  • 1
  • 1
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73