Can't build RDCOMClient using rtools40 and R 4.0

A while back, I created a fork of the RDCOMClient package to keep it working with R 3.6 (). People are now running into issues again because it won't work with R 4.0. The problem doesn't seem as easy to fix, and I'm hoping for some help.

If I flip Rstudio back to R 3.6 (and rtools35), I can use the package after installing with devtools::install_github(). When I try in R 4.0 (and rtools40), the package builds and I can connect over COM to an application. The first line of code below works, and xl is a COM pointer; however, trying to do anything with it (like set Excel to visible) will crash R.

xl <- RDCOMClient::COMCreate("Excel.Application") xl[["Visible"]] <- TRUE 

Again, the above works in R 3.6.

Is there is a way to continue building with the previous rtools? I came across , which talks about using rtools35 to keep building packages, so I have hope, but I don't understand how to make it happen.

Alternatively, if there are minor changes I can make to the R or cpp code that will solve my problem, I'm all ears. I'm a cpp novice, though.

6 Answers

This was a quick fix :

install.packages("RDCOMClient", repos = "")

2
  1. Install R-4.0.0
  2. Install Rtools35
  3. Edit $R_HOME/etc/x64/Makeconf (for R-4.0.0-x64)
  4. Rcmd INSTALL RDCOMClient
1

Rik's answer was incredibly helpful and got a version working; however, after spending a day on it, I was able to improve on it. I want to put that here in case I have to do it again. The main improvement is being able to build a working package for both 32- and 64-bit architectures. By default, R installs both, and this makes things easier when installing dependent packages.

The first two steps are the same:

Install R-4.0.0 ()

Install Rtools35 () in directory c:\Rtools

If (like me) you had already installed rtools40, a system environment variable named RTOOLS40_HOME is created. The first step is to change that to:

C:\rtools

If you don't have rtools40 installed, then create the RTOOLS40_HOME system environment variable.

Two changes are still needed in the make files. These are found in your R installation directory.

In etc\x64\Makeconf, add underscores to match the rtools35 directory structure by setting these values:

MINGW_PREFIX = /mingw_$(WIN) BINPREF ?= "$(RTOOLS40_ROOT)/mingw_64/bin/" 

Do the same in etc\i386\Makeconf:

MINGW_PREFIX = /mingw_$(WIN) BINPREF ?= "$(RTOOLS40_ROOT)/mingw_32/bin/" 

Do not set BINPREF as an environment variable, or this will overwrite the makefile changes (like RTOOLS40_HOME does). With these complete, finish off with the same steps that Rik outlined:

Open windows command prompt and change to the directory that contains the RDCOMClient subdirectory and type:

R CMD INSTALL RDCOMClient –-build RDCOMClient.zip

This installs RDCOMClient in the local installation of R-4.0.0 and additionally creates the file RDCOMClient_0.94-0.zip that can be installed on other systems using the following command:

install.packages("RDCOMClient_0.94-0.zip", repos = NULL, type = "win.binary")

2

I can confirm that the procedure delineated in the answer above leads in the right direction but a few extra steps may be required. I can also confirm that the procedure below produces a Windows binary file that can be installed and will run under R-4.0.0:

Install R-4.0.0 ()

Install Rtools35 () in directory c:\Rtools

Edit $R_HOME/etc/x64/Makeconf (for R-4.0.0-x64) by changing

## The rtools40 installer sets RTOOLS40_HOME, default to standard install path RTOOLS40_HOME ?= c:/rtools40 

to

## The rtools40 installer sets RTOOLS40_HOME, default to standard install path RTOOLS40_HOME ?= c:/rtools 

Download RDCOMClient-master.zip from (click the green Clone button and select download zip)

Unpack to a directory named RDCOMClient

Ensure that the following PATH variables are set:

C:\Program Files\R\R-4.0.0\bin\x64 (assuming this is the location where R is installed) C:\Rtools\bin C:\Rtools\mingw_64\bin 

Add environment variable BINPREF with the following value (the final slash is important):

C:/Rtools/mingw_64/bin/ 

Open windows command prompt and change to the directory that contains the RDCOMClient subdirectory and type:

R CMD INSTALL RDCOMClient –-build RDCOMClient.zip 

This installs RDCOMClient in the local installation of R-4.0.0 and additionally creates the file RDCOMClient_0.94-0.zip that can be installed on other systems using the following command:

install.packages("RDCOMClient_0.94-0.zip", repos = NULL, type = "win.binary") 
1

I am using R 4.1.2 and I found RDCOMClient will crash the R Session and the above solutions were not working.

Then, I further check with the source owner and found out the solution.

Duncantl gave the solution and it works.

dir.create("MyTemp") remotes::install_github("BSchamberger/RDCOMClient", ref = "main", lib = "MyTemp") 

If that is successful, we can then load the newly installed package with

library("RDCOMClient", lib.loc = "MyTemp") 

although this post is a bit older but i also stumbled across it since i had a similar issue. what worked for me at the end was the following command in the R console:

devtools::install_github("omegahat/RDCOMClient") 

i had to install a lot of other packages to be able to run it but that you will get from the warning messages from R. I am using R version 4.3.0 (2023-04-21 ucrt)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like