From ggrothendieck at gmail.com  Wed Jun 24 12:39:06 2009
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 24 Jun 2009 06:39:06 -0400
Subject: [Rd] loadNamespace and useDynLib
In-Reply-To: <AC97AFA9-3CA1-4D31-9E77-E116D44A78C1@stat.berkeley.edu>
References: <AC97AFA9-3CA1-4D31-9E77-E116D44A78C1@stat.berkeley.edu>
Message-ID: <971536df0906240339v74f87838n166fe96e3dcdc89d@mail.gmail.com>

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
>



[Rd] loadNamespace and useDynLib
Gabor Grothendieck