[R-pkg-devel] "LoadLibrary failure" on Windows

Duncan Murdoch murdoch.duncan at gmail.com
Tue Dec 19 16:16:28 CET 2017


On 19/12/2017 6:15 AM, Sarah Friedrich wrote:
> Dear all,
> 
> the CRAN Package Check Results for my package GFD indicate an error on
> windows (https://cran.r-project.org/web/checks/check_results_GFD.html),
> which I am unable to fix. In my package, I'm using RGtk2 for creating a
> GUI. Since this produced errors before, I first check if RGtk2 is
> available via
> 
> requireNamespace("RGtk2", quietly = TRUE)
>     if(!("package:RGtk2" %in% search())){attachNamespace("RGtk2")}

That code doesn't quite make sense.  Some background first:

A package can be "loaded" or "loaded and attached".  If your DESCRIPTION 
file has the package in the Imports list, it will be automatically 
loaded.  If it is in the Depends list, it will be automatically loaded 
and attached.  But if it is in the Suggests list, neither of these will 
happen automatically.

If a package is loaded but not attached, then it will not be on the 
search list.

You can load a package using requireNamespace().  Your first line of 
code does that.  If the package has already been loaded, nothing will 
happen.  You can load and attach it using require().  Both of these 
functions return a logical value to indicate success.

You almost never need to call attachNamespace.  If you really need to 
have the package on the search list (and this is rare), you should have 
called require().  Usually you just need code like this:

  if (!requireNamespace("RGtk2", quietly = TRUE))
    # Signal that RGtk2 is not available.

If the error didn't happen, then RGtk2 is now guaranteed to be loaded, 
and you can call functions from it using code like

RGtk2::foo()

If you don't want to always use the prefix RGtk2::, then you could have 
used require("RGtk2", quietly = TRUE) when you loaded it, but this is 
frowned upon, because the user might not want RGtk2 in their search 
list.  (It might have functions with the same names as functions from 
other packages, and that can mess up the user's code.)

Duncan Murdoch
> 
> It all works fine on linux (x86_64-suse-linux-gnu (64-bit)) and on R
> version 3.2.5 on windows (x86_64-w64-mingw32/x64 (64-bit)), so I suspect
> that it's not actually an error in my package but something between
> RGtk2 and the new R version on windows. Anyway, a workaround would be
> greatly appreciated! Do you have any suggestions?
> 
> Thanks a lot in advance and best regards,
> Sarah
> 
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list