Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RDCOMClient error - No support for InterfaceSupportsErrorInfo

I am running a daily task in R which retrieves an email (which has a csv file attached) from my Outlook, performs some analysis on the csv file and writes a resulting data frame to a local drive in my company. Some mornings I find that the files have not been delivered, and according to the logs the reason is the following error:

<checkErrorInfo> 80020009 
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
Execution halted

I can't find any pattern to the days where this happens and the days where it doesn't. Once I go and trigger the task manually, it usually runs fine.

I've seen this error raised in other questions, but those have been related to sending an attachment via Outlook, which I'm not doing. Below is my code for accessing outlook and retrieving the data:

library(RDCOMClient)    

outlook_app <- COMCreate("Outlook.Application")

search <- outlook_app$AdvancedSearch(
  "Inbox",
  "urn:schemas:httpmail:subject = 'My_Subject'"

)
Sys.sleep(5)

results <- search$Results()

for (i in 1:results$Count()) {
  if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime()) 
      == as.Date(strptime(Sys.time(),format = "%Y-%m-%d"))) {
    email <- results$Item(i)
  }
}

attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
data <- read.csv(attachment_file,sep=",",fileEncoding="UCS-2LE")
like image 495
John F Avatar asked Dec 15 '17 14:12

John F


1 Answers

Is it possible that there is no file there at the time your code is run, or your sys.sleep is too short?

like image 123
Mark Neal Avatar answered Oct 11 '22 12:10

Mark Neal