title: R "for loop" error messages {}
body: <p>Since a couple of days ago when I run a for loop in R it gives me plenty of errors related to "}". It only happens if I highlight the whole code and run it. If i execute it line by line, then it runs just fine. </p>
  
  <p>I tried even with the most basic loop:</p>
  
  <pre><code>foo &lt;- seq(1, 100, by=2)
  foo.squared &lt;- NULL
  for (i in 1:50 ) {
  foo.squared[i] &lt;- foo[i]^2
  }
  </code></pre>
  
  <p>Here is the console: </p>
  
  <pre><code>&gt; foo &lt;- seq(1, 100, by=2)
  "rror: unexpected input in "foo &lt;- seq(1, 100, by=2)
  &gt; foo.squared &lt;- NULL
  "rror: unexpected input in "foo.squared &lt;- NULL
  &gt; for (i in 1:50 ){
  "rror: unexpected input in "for (i in 1:50 ){
  &gt; foo.squared[i] &lt;- foo[i]^2
  "rror: unexpected input in " foo.squared[i] &lt;- foo[i]^2
  &gt; }
  Error: unexpected '}' in "}"
  &gt; 
  </code></pre>
  
  <p>Details of the R session (I run it in RStudio):</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.0.2 (2013-09-25)
  Platform: x86_64-apple-darwin10.8.0 (64-bit)
  </code></pre>
  
  <p>It has been very annoying!! I would appreciate any advice!!!
  Thanks,
  Maria</p>
  
  <p>UPDATE:</p>
  
  <p>Here is the code in the very beginning that I suspect causes this problem..It is supposed to take a vector of names and extract the second element from it.</p>
  
  <pre><code>splitnames &lt;- strsplit(as.character(train$Name),"[,.]")
  firstelement &lt;- function(x){x[2]}
  sapply(splitnames,firstelement)
  </code></pre>
  
  <p>After I execute it R acts weird. Though I am not 100% sure. </p>