R:为什么"是"是真的,但"as"是不可能的?

mra*_*a68 5 r

类"ECDF"从类"stepfun"继承.如果f是这样的经验累积密度函数,都is.stepfun(f)is(f,"stepfun")TRUEas.stepfun(f)预期没有做任何事情.但是由于"元数据",转换f为"stepfun" as(f,"stepfun")是不可能的,即使strictFALSE:

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
Run Code Online (Sandbox Code Playgroud)

那么这里的"元数据"是如何is相关的as呢?

Car*_*oft 2

我可能找到了一些相关信息。在这个令人费解的档案中

but it has two problems: 

1) as() is an S4 method that does not always work 
(problem 2 not relevant)
Run Code Online (Sandbox Code Playgroud)

本地:-) 这个问题 有关于尝试使用的警告as()

所以我的建议是坚持使用 as.stepfun(foo) .