[R-pkg-devel] re-exporting plot method?

Kevin R. Coombes kev|n@r@coombe@ @end|ng |rom gm@||@com
Tue Apr 30 20:03:31 CEST 2024


Hi,

I am working on a new package that primarily makes use of "igraph" 
representations of certain mathematical graphs, in order to apply lots 
of the comp sci algorithms already implemented in that package. For 
display purposes, my "igraph" objects already include information that 
defines node shapes and colors and edge styles and colors. But, I 
believe that the "graph" - "Rgraphviz" - "graphNEL" set of tools will 
produce better plots of the graphs.

So, I wrote my own "as.graphNEL" function that converts the "igraph" 
objects I want to use into graphNEL (or maybe into "Ragraph") format in 
order to be able to use their graph layout and rendering routines. This 
function is smart enough to translate the node and edge attributes from 
igraph into something that works correctly when plotted using the tools 
in Rgraphviz. (My DESCRIPTION and NAMESPACE files already import the set 
of functions from Rgraphviz necessary to make this happen.)

In principle, I'd like the eventual user to simply do something like

library("KevinsNewPackage")
IG <- makeIgraphFromFile(sourcefile)
GN <- as.graphNEL(IG)
plot(GN)

The first three lines work fine, but the "plot" function only works if 
the user also explicitly includes the line

library("Rgraphviz")

I suspect that there is a way with imports and exports in the NAMESPACE 
to make this work without having to remind the user to load the other 
package. But (in part because the plot function in Rgraphviz is actually 
an S4 method, which I don't need to alter in any way), I'm not sure 
exactly what needs to be imported or exported.

Helpful suggestion would be greatly appreciated.

Best,
   Kevin



More information about the R-package-devel mailing list