TobyT
TobyT

Reputation: 83

Determining which R packages, and dependencies, use DLL files

I work in a corporate environment that uses Microsoft Windows Defender Application Control (WDAC) to provide security. This blocks unsigned EXE and DLL files from being installed on devices. R packages which use DLLs fail to install. The workaround to this is provide an R installation from an approved central source which also copies over a default set of packages, such as tidyverse, data.table etc. to the R library. Users can continue to install additional packages which are built with native R, but run into issues if they try to install, build from source, or update packages with DLL files in.

Is there a way to check whether a package uses DLL files in advance of installation?

Output something like:-

check_dll(foo)
result: "This package and its dependencies have no DLL files. You can install this package"

check_dll(bar)
result: "bar does not have any DLL files, but one dependency, OOF, uses DLL files. 
You have already have a version of OOF installed so it should be safe to install bar"

check_dll(foobar)
result: "foobar has a DLL. Do not attempt to install foobar".

check_dll(RABOOF)
result: "RABOOF does not have any DLL files, but one of it's dependencies, 
foobar, does have a DLL file. Do not attempt to install RABOOF".

tools::package_dependencies() will list the package dependencies, but nothing else.

Downloading the zip file from CRAN and inspecting it for a libs/x64 folder with contents will work, but seems a heavyweight approach. Theoretically if a package has lots of dependencies this could result in downloading a lot of files unnecessarily.

Upvotes: 2

Views: 295

Answers (2)

TobyT
TobyT

Reputation: 83

I have accepted the answer from user2554330 as the best solution. It makes use of the normal set of commands used for package management; and the matrix generated by available.packages() can be passed to tools::package_dependencies(), removing the need for multiple internet queries.

For completeness I am documenting another possible solution. A script could query the unofficial CRAN Github mirror https://docs.r-hub.io/#cranatgh and look for a /src directory in each package project.

Upvotes: 1

user2554330
user2554330

Reputation: 44887

Look for the NeedsCompilation field in the DESCRIPTION file. If it is "yes", there will be a DLL. If it is "no", there probably won't be. (If it is not there, the package wasn't built properly, so all bets are off.)

The test is not perfect, because packages can put DLLs into the inst folder to get them installed without compiling them, though CRAN isn't supposed to allow that: "Source packages may not contain any form of binary executable code." But packages like pak (mentioned in the comments) may be allowed to get around this rule, e.g. by downloading binaries, so the test isn't perfect. You will also need to put together a blacklist of packages that will fail your WDAC tests even though they claim not to need compilation, containing pak and others like it.

The NeedsCompilation field is included as a column of the result of available.packages(), so it is very easy to access without trying to install the package.

Upvotes: 2

Related Questions