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
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
I've also experienced this problem with RGraphviz and suggest you expand the message to: Graphviz version x found at c:\...whatever...\graphviz.dll but version y found at http://whatever required. Another approach would be to check that the file size, file name, checksum or some other attribute of the needed version matches the version found. That way you could give the error message before loading the dll. A third approach would be to provide an R command that downloads and installs the correct version of graphviz to reduce the possibility of error in the first place. The user must be connected to the internet for that to work. For example, in Ryacas, if yacas itself is not located when the package loads a message is given to run the command: yacasInstall() Running that command from within R downloads the correct yacas*.zip file, unpacks it and installs the components. See: http://ryacas.googlecode.com/svn/trunk/R/yacasInstall.R http://ryacas.googlecode.com/svn/trunk/man/yacasInstall.Rd That won't prevent the wrong version from being used but it makes it much less likely. On Wed, Jun 24, 2009 at 1:46 AM, Kasper Daniel Hansen<khansen at stat.berkeley.edu> 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). > > 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 >