[Rd] loadNamespace and useDynLib

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Jun 24 12:05:52 CEST 2009



Kasper Daniel Hansen wrote:
> 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).


At first, I do not answer your question, but make your request more 
complicated:

It is even hard to find "version XXX of Graphviz", because the numbers 
in the names of the distributed graphviz zip files and the actual 
versions of graphviz are also not always the same. Beside that the 
graphviz folks obviously even change API specifications in patch-level 
releases.

Then to your question: I think your are right and need it in .onLoad 
where you can finally check if the dll has been loaded and generate erro 
messages.

Good luck,
Uwe



> I could see the use for this for other packages that depends on external 
> DLLs.
> 
> Thanks
> Kasper
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list