In developing an R package, how do I import the as()
method for an S4 class?
More details: I need to convert an adjacency matrix to a graphNEL object (from the graph
package). Here is the code for doing so:
library("graph")
m <- rbind(
c(0, 0, 0, 0),
c(1, 0, 0, 0),
c(0, 1, 0, 0),
c(0, 0, 1, 0)
)
gr <- as(m, "graphNEL")
Unfortunately, this code fails in an R package:
Error in as(m, "graphNEL") :
no method or default for coercing “matrix” to “graphNEL”
The issue appears to be importing the required as()
method, but I cannot seem to figure out how to do this. Note that this still fails if the graph package is included in Imports
.