Using the code below to pull a .csv file from Microsoft Outlook into R for routine data manipulation and keep getting the following error (specifically after running the results lines):
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
Similar posts in Stack Overflow suggested adding sys.sleep()
to fix this issue, allowing the system adequate time to search through e-mail subjects. After adding sys.sleep()
with various time frames (ranging from 5-50), I'm still getting this error. Any suggestions or advice?
#Load in dataset from e-mail
outlook_app <-COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpsmail:subject = 'Outcome Information to Date'"
)
Sys.sleep(5)
results <- search$Results()
Sys.sleep(5)
for (i in 1:results$Count()) {
if(as.Date("1899-12-30")+floor(results$Item(i)$RecievedTime())
== as.Date(strptime(Sys.time(),format="%Y-%m-%d"))) {
email <- results$Item(i)
}
}
attachment_file<-tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
#Save outcome data in a dataframe
outcomedata<-read.csv(attachment_file)