[Rd] Telling Windows how to find DLL's from R?

Thomas Baier thomas.baier at logicals.com
Tue Jul 13 11:51:44 CEST 2010


Dominick,

Dominick Samperi wrote:
> On Fri, Jul 9, 2010 at 3:48 PM, Duncan Murdoch
> <murdoch.duncan at gmail.com>wrote: 
> 
>> On 09/07/2010 2:38 PM, Dominick Samperi wrote:
>> 
>>> Is it possible to set Windows' search path from within R, or to tell 
>>> Windows how to find a DLL in some other way from R? Specifically, if 
>>> a package DLL depends on another DLL the normal requirement is that 
>>> the second DLL be in the search path so Windows can find it (there 
>>> are other tricks, but they apply at the Windows level, not at the R 
>>> level).
>>> 
>>> 
>> 
>> 
>> I haven't tried this, but can't you use Sys.setenv() to change the 
>> PATH to what you want?  Presumably you'll want to change it back 
>> afterwards.
>> 
> 
> Thanks, good suggestion, but it does not seem to work. If PATH is 
> updated in this way the change is local to the current process, not to 
> the top-level Windows process, so a subsequent
> dyn.load('foo.dll') will fail if foo.dll depends on bar.dll, unless 
> bar.dll is placed in the search path for the top-level shell. Seems 
> like this needs to be done as part of system startup outside of R.
> 
> On the other hand, if foo.dll is the package library for package foo, 
> and if foo depends on package bar, then there is no need to place 
> bar.dll in the top-level search path. R takes care of this (more
> typical) situation.   

there is another Windows "feature" which will do the trick for you without
modifying the search path. Windows normally only loads DLLs once, so this
means if you first load the dependent DLL (manually, e.g. using dyn.load())
then the already loaded DLL will be used instead of trying to load one from
path.

E.g. in your example:

	dyn.load("mypath/bar.dll")
	dyn.load("foo.dll")

will work, as bar.dll (a dependency of foo.dll) is already loaded.

Thomas



More information about the R-devel mailing list