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

From: Thomas Baier <>
Date: Tue, 13 Jul 2010 11:51:44 +0200


Dominick Samperi wrote:
> On Fri, Jul 9, 2010 at 3:48 PM, Duncan Murdoch
> <>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:


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

Thomas mailing list Received on Tue 13 Jul 2010 - 09:57:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 13 Jul 2010 - 13:10:15 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive