title: Use main function in R
body: <p>I've been using R for 4 months now, and I really hope there is a way to use <code>main</code> function as in other languages (C++, Python...)</p>
  
  <p>The main reason I want to do this is that all the variables I use in a R script are global variables that can potentially pollute the namespace of the functions I defined in the same script:</p>
  
  <pre><code>f &lt;- function(x) {
    x + a
  }
  a &lt;- 50
  f(5)
  </code></pre>
  
  <p>For me, this is just a personal preference. I'm a sloppy programmer and I want to prevent myself from making silly mistakes. </p>
  
  <p>I can surely define <code>main &lt;- function() {}</code>, but I want to know if there is anything similar to this:</p>
  
  <pre><code>if __name__ == "__main__": 
      main()
  </code></pre>
  
  <p>(In this Python script, if the function name is <code>main</code>, then run <code>main()</code> to call the main function.)</p>