title: Global and local variables in R
body: <p>I am a newbie for R, and I am quite confused with the usage of local and global variables in R.</p>
  
  <p>I read some posts on the internet that say if I use <code>=</code> or <code>&lt;-</code> I will assign the variable in the current environment, and with <code>&lt;&lt;-</code> I can access a global variable when inside a function.</p>
  
  <p>However, as I remember in C++ local variables arise whenever you declare a variable inside brackets <code>{}</code>, so I'm wondering if this is the same for R? Or is it just for <em>functions</em> in R that we have the concept of local variables.</p>
  
  <p>I did a little experiment, which seems to suggest that only brackets are not enough, am I getting anything wrong?</p>
  
  <pre><code>{
     x=matrix(1:10,2,5)
  }
  print(x[2,2])
  [1] 4
  </code></pre>