title: How to pass an argument while calling the R function from .Net using R.Net
body: <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Xml.Linq;
  using Outlook = Microsoft.Office.Interop.Outlook;
  using Office = Microsoft.Office.Core;
  using RDotNet;
  using RDotNet.NativeLibrary;
  
  namespace OutlookAddinSendMailToWebService
  {
      public partial class ThisAddIn
  {
      #region Variables
      private Outlook.Explorer activeExplorer = null;
      #endregion
  
      private void ThisAddIn_Startup(object sender, System.EventArgs e)
      {
          activeExplorer = Application.ActiveExplorer();
      }
  
      private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
      {
      }
  
      //Send Message to Webservice
      public void SendMailToWebservice()
      {
          string mailTo = String.Empty;
          string mailCC = String.Empty;
          string mailSubject = String.Empty;
          string mailBody = String.Empty;
          string mail = String.Empty;
  
          REngine.SetEnvironmentVariables();
          // There are several options to initialize the engine, but by default the following suffice:
          REngine engine = REngine.GetInstance();
  
          if (activeExplorer.Selection.Count &gt; 0)
          {
              foreach (Object selectedItem in activeExplorer.Selection)
              {
                  if (selectedItem is Outlook.MailItem)
                  {
                      Outlook.MailItem mailItem = (selectedItem as Outlook.MailItem);
                      if (mailItem != null)
                      {
                          mailCC = "CC: " + mailItem.CC;
                          mailTo = "To: " + mailItem.To;
                          mailSubject = "Subject: " + mailItem.Subject;
                          mailBody = "Body: " + mailItem.Body;
                          mail = mailTo + '\n' + mailCC + '\n' + mailSubject + '\n' + mailBody;
                          //System.Windows.Forms.MessageBox.Show(mail);
  
                          engine.Evaluate("load('~/key.RData')");
                          var key = engine.Evaluate("key(mail)").AsCharacter()[0];
  
                          engine.Evaluate("load('~/add.RData')");
                          var add = engine.Evaluate("trim(key)").AsCharacter()[0];
  
                          engine.Evaluate("load('~/match.RData')");
                          var mat = engine.Evaluate("match(add,key)").AsCharacter()[0];
  
                          System.Windows.Forms.MessageBox.Show(mat);
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>Iam getting error in the following lines of code.Its giving the error as argument mail is not found when iam trying to call key function.</p>
  
  <pre><code>engine.Evaluate("load('~/key.RData')");
  var key=engine.Evaluate("key(mail)").AsCharacter()[0];
  engine.Evaluate("load('~/add.RData')");
  var add = engine.Evaluate("trim(key)").AsCharacter()[0];
  engine.Evaluate("load('~/match.RData')");
  var mat = engine.Evaluate("match(add,key)").AsCharacter()[0];
  </code></pre>