omegahat/RDCOMClient

R 4.0.1 and RDCOMClient 0.94 R Session Aborted

yanlesin opened this issue ยท 8 comments

Hi @omegahat , I noticed the following error when using RDCOMClient with R 4.0.1 on Windows 10: Outlook$CreateItem(0) line causes R to crash. R 3.6.3 is working fine. Within RStudio 1.3.959 it exists with error "Session Aborted", but command line R just crashes (this is not RStudio issue).
library(RDCOMClient)
Outlook <- COMCreate("Outlook.Application")
Email = Outlook$CreateItem(0) ##This is line that causes R to crash

I have the same problem, the R session is aborted. Also with R 4.0.1
With the last line, it crashes

file <- "13006220q111.xlsx" # relative path to Excel file
ex <- COMCreate("Excel.Application") # create COM object
file <- getAbsolutePath(file) # convert to absolute path
book <- ex$workbooks()$Open(file) # open Excel file

@RikSchoemaker and I compiled a binary version of this package that will work in R 4.0.x. I've put it up on my fork of this repo, and you can use the code below to install it.

dir <- tempdir()
zip <- file.path(dir, "RDCOMClient.zip")
url <- "https://github.com/dkyleward/RDCOMClient/releases/download/v0.94/RDCOMClient_binary.zip"
download.file(url, zip)
install.packages(zip, repos = NULL, type = "win.binary")

For details on the creation of the file, see the stackoverflow page. In short, we didn't modify the C++ code, but merely used the older rtools35 to compile it.

This should work for a while, but I'm still hoping @duncantl can find time to do a true update to the package.

I have also been facing issues with crashes when trying to run the 0.94-0 version under R 4.0.x. I created a minimal commit that fixes the immediate crash issues (for me). The problem appears to be the package's attempt to create an error log at C:/RDCOM.err. Disabling the automatic creation has helped for me. Re-enabling errors and trying to write into an non-existing directory currently still leads to a crash for me.

You can find the commit at BSchamberger/RDCOMClient@68c94c5
If someone wants to give it a try, you can install it via

library(remotes) 
remotes::install_github("BSchamberger/RDCOMClient", ref = "main")
remotes::install_github("BSchamberger/RDCOMClient")

I tried to install it but got the message:
> remotes::install_github("BSchamberger/RDCOMClient") Downloading GitHub repo BSchamberger/RDCOMClient@master Error in utils::download.file(url, path, method = method, quiet = quiet, : cannot open URL 'https://api.github.com/repos/BSchamberger/RDCOMClient/tarball/master'

remotes::install_github("BSchamberger/RDCOMClient")

I tried to install it but got the message:
> remotes::install_github("BSchamberger/RDCOMClient") Downloading GitHub repo BSchamberger/RDCOMClient@master Error in utils::download.file(url, path, method = method, quiet = quiet, : cannot open URL 'https://api.github.com/repos/BSchamberger/RDCOMClient/tarball/master'

What version of the remotes package are you using? It works as expected on version 2.2.0.
It looks like your version is looking for a branch called "master", which does not exist. You may try

remotes::install_github("BSchamberger/RDCOMClient", ref = "main")

For good measure, I have also created an identical branch called "master", so it might work now

Thanks for your reply!
I was on remotes version 2.1.1 but the change you made seems to have worked because the install worked this time.

@BSchamberger this looks pretty excellent. Just so I'm clear: with your changes, the package will compile natively in R4.x (using rtools40) and not hang when attempting to call things over COM? If so, that's fantastic news. You can see my pull request #20

Would you create a pull request for your work here, too? My hope is to get everything merged back in here. In the meantime, I'll likely bring your changes into my own fork.

@dkyleward with that commit I tried to do a minimal change to prevent R from crashing when using the package/call things over COM. For me it compiles in R4.x with rtools40 both with and without this change (under Windows 10).

In the meantime, I have done some more changes that resolve the compiler warnings the package currently gets (with rtools40), give more control over the error log file and provide additional exception information for COM (where available). You can find it here BSchamberger/RDCOMClient@main...error_handling . It may make more sense to create a pull request for that version