title: R-studio server returns error after simple if-else code execution
body: <p>I am currently facing this problem. Analyzing a big data-set (roughly 3 million observations), I need to convert a variable from a format to another. Specifically, I had the date of incorporation of several firms, but coming in two formats: <code>YYYY</code> or <code>MM-DD-YYYY</code>, or other possibilities of which the last 4 characters were always relative to the year. </p>
  
  <p>What I need is just the year so I developed this code: </p>
  
  <pre><code>library(stringi)
  
  for (i in 1:length(amadeus$Dateofincorporation) {
      if(nchar(amadeus$Dateofincorporation[i]) == 4 &amp; 
         !is.na(amadeus$Dateofincorporation[i])) {
          amadeus$Dateofincorporation[i] &lt;- amadeus$Dateofincorporation[i]
      } 
      else if (nchar(amadeus$Dateofincorporation[i]) != 4 &amp; 
               !is.na(amadeus$Dateofincorporation[i])) {
          amadeus$Dateofincorporation[i] &lt;- stri_sub(amadeus$Dateofincorporation[i],-4,-1)
      } 
      else { 
          amadeus$Dateofincorporation[i] &lt;- amadeus$Dateofincorporation[i] 
      }
  }
  </code></pre>
  
  <p>The code executes for a long time, and then returns the output:</p>
  
  <blockquote>
    <p>Warning messages: 1: In doTryCatch(return(expr), name, parentenv,
    handler) :   display list redraw incomplete 2: In
    doTryCatch(return(expr), name, parentenv, handler) :   invalid
    graphics state 3: In doTryCatch(return(expr), name, parentenv,
    handler) :   invalid graphics state 4: In doTryCatch(return(expr),
    name, parentenv, handler) :   display list redraw incomplete 5: In
    doTryCatch(return(expr), name, parentenv, handler) :   invalid
    graphics state 6: In doTryCatch(return(expr), name, parentenv,
    handler) :   invalid graphics state</p>
  </blockquote>
  
  <p>Does anyone have an idea on how to deal with this?</p>
  
  <p>P.S. the vector is currently a character vector, do you think this has an impact?</p>