【问题标题】:R `as` method for converting custom S4 class用于转换自定义 S4 类的 R`as` 方法
【发布时间】:2021-02-17 08:27:01
【问题描述】:

我正在开发一个 R 包,并希望包含一个覆盖 igraph::as.igraph() 并允许用户将我的自定义类转换为 igraph::igraph 对象的函数。这样做的正确方法是什么?

【问题讨论】:

    标签: r type-conversion package s4 coercion


    【解决方案1】:

    从 igraph 包中导入泛型,并为你的类导出你的方法。

    #' @importFrom igraph as.igraph
    NULL
    
    #' @export
    as.igraph.yourclass <- function(x, ...)
    {
        your code here
    }
    
    

    【讨论】:

    • 我可以让as.igraph.yourclass 工作,但是当我只使用as.igraph 时仍然出现此错误:Error in UseMethod("as.igraph") : no applicable method for 'as.igraph' applied to an object of class "network"
    • 重新记录您的包裹
    • 成功!谢谢
    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    相关资源
    最近更新 更多