Search code examples
rtype-conversionpackager-s4coercion

R `as` method for converting custom S4 class


I'm developing an R package and want to include a function that overrides igraph::as.igraph() and lets users convert my custom class into an igraph::igraph object. What's the correct way to do this?


Solution

  • Import the generic from the igraph package, and export your method for your class.

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