title: Downloading attachment from Outlook into R
body: <p>Following Greg Thatcher's answer (accepted answer) to <a href="https://stackoverflow.com/questions/42573699/how-to-retrieve-outlook-inbox-emails-using-r-rdcomclient/42590894">How to retrieve Outlook inbox emails using R RDCOMClient?</a>, I wrote some code to search through my inbox and find an email report I receive everyday. The code begins with - </p>
  
  <pre><code>library(RDCOMClient)
  
  folderName = "Inbox"
  
  OutApp = COMCreate("Outlook.Application")
  outlookNameSpace = OutApp$GetNameSpace("MAPI")
  folder = outlookNameSpace$Folders(1)$Folders(folderName)
  emails = folder$Items
  </code></pre>
  
  <p>This was working last week but systems typically restart over the weekend, and now this is not working, and I have no idea why. I get an error on the second to last line in the code snippet <code>outlookNameSpace$Folders(1)$Folders(folderName)</code> - </p>
  
  <pre><code>&lt;checkErrorInfo&gt; 80020009 
  No support for InterfaceSupportsErrorInfo
  checkErrorInfo -2147352567
  Error: Exception occurred.
  </code></pre>
  
  <p>However, in trying to troubleshoot, I came across <a href="https://stackoverflow.com/questions/45577698/download-attachment-from-an-outlook-email-using-r/45665974#comment82670681_45665974">Download attachment from an outlook email using R</a> using which I wrote out -  </p>
  
  <pre><code>library(RDCOMClient)
  
  OutApp = COMCreate("Outlook.Application")
  search = OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject = 'Finding Memo - Specific Theme'")
  </code></pre>
  
  <p>This seems to work because I get the right number when I do <code>search$Results()$Count()</code>.</p>
  
  <p>Problem is I cannot (or do not know how to) use this second method for my process because the while the beginning part of the subject of the email report stays the same, the end keeps changing. The first method allows me to use <code>grepl()</code> on the subject of the emails.</p>
  
  <p>If someone could help me understand what is causing first method to break or guide me on modifying the second method to work with <code>grepl()</code>? </p>