[Rd] loadNamespace and useDynLib

Kasper Daniel Hansen khansen at stat.berkeley.edu
Wed Jun 24 07:46:43 CEST 2009


I am considering a package with a namespace (Rgraphviz from Bioc). I  
essentially want to have some error handling for loading the dll,  
something like wrapping it into tryCatch or similar (reason: see  
below). Right now I am loading the dynamic libraries by useDynLib in  
my NAMESPACE file. When I look at the code from loadNamespace, I have  
the impression that what I want is impossible (.onLoad and the user  
settable hooks are called after the dynamic libraries have been  
loaded). Is that true? And is the only way to proceed, to not use  
useDynLib in my NAMESPACE file, but instead load the dynamic libraries  
manually in .onLoad?

Reason for my wish: on Windows Rgraphviz links to Graphviz which the  
user needs to install themselves. Unfortunately there are many  
versions of Graphviz and they tend to be incompatible with each other,  
to the extent that certain libraries have been renamed. This has been  
causing a lot of confusion since the Windows binaries have been  
compiled with one specific version, and sometimes the loading of the  
dll itself fails because the libraries have been renamed.... I am  
attempting to inject some kind of helpful error message along the  
lines of "it looks like you did not have version XXX of Graphviz  
installed". For that to happen, I need to do a tryCatch. There is a  
potential similar problem for binaries on OS X (but somewhat fewer  
complaints).

I could see the use for this for other packages that depends on  
external DLLs.

Thanks
Kasper



More information about the R-devel mailing list