title: R: how to use get and set functions in a package?
body: <p>I am trying my hand at R, along with RStudio and I am currently stuck. Is it possible to create an R package with a variable visible only inside of that package? I was unable to find comprehensive examples on the web.</p>
  
  <p>Here's a small example:</p>
  
  <pre><code>gEnv &lt;- new.env()
  
  a &lt;- ""
  b &lt;- "Beta"
  assign(a, "alpha", envir=gEnv)
  assign(b, "beta", envir=gEnv)
  
  getA &lt;- function()
  {
    return(get(a, envir=gEnv))
  }
  
  getB &lt;- function()
  {
    return(get(b, envir=gEnv))
  }
  
  setA &lt;- function(x)
  {
    return(assign(a, x, envir=gEnv))
  }
  
  setB &lt;- function(x)
  {
    return(assign(b, x, envir=gEnv))
  }
  </code></pre>
  
  <p>When I try to 'Build &amp; Reload', I get the following error:</p>
  
  <pre><code>==&gt; Rcmd.exe INSTALL --no-multiarch --with-keep.source globalVar
  
  * installing to library 'C:/Users/*masked*/Documents/R/win-library/3.2'
  * installing *source* package 'globalVar' ...
  ** R
  ** preparing package for lazy loading
  Error in assign(a, "alpha", envir = gEnv) : 
    attempt to use zero-length variable name
  Error : unable to load R code in package 'globalVar'
  ERROR: lazy loading failed for package 'globalVar'
  * removing 'C:/Users/*masked*/Documents/R/win-library/3.2/globalVar'
  
  Exited with status 1.
  </code></pre>
  
  <p>How can the above code be changed to successfully build a package, from which I can later call <code>setA("apple")</code> and <code>getA()</code> would actually return <code>[1] "apple"</code>?</p>