【发布时间】:2021-02-17 08:27:01
【问题描述】:
我正在开发一个 R 包,并希望包含一个覆盖 igraph::as.igraph() 并允许用户将我的自定义类转换为 igraph::igraph 对象的函数。这样做的正确方法是什么?
【问题讨论】:
标签: r type-conversion package s4 coercion
我正在开发一个 R 包,并希望包含一个覆盖 igraph::as.igraph() 并允许用户将我的自定义类转换为 igraph::igraph 对象的函数。这样做的正确方法是什么?
【问题讨论】:
标签: r type-conversion package s4 coercion
从 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"