title: Examining contents of .rdata file by attaching into a new environment - possible?
body: <p>I am interested in listing objects in an RDATA file and loading only selected objects, rather than the whole set (in case some may be big or may already exist in the environment).  I'm not quite clear on how to do this when there are conflicts in names, as <code>attach()</code> doesn't work as nicely.</p>
  
  <p>1: For examining the contents of an R data file without loading it: This question is similar, but different from, the one asked at <a href="https://stackoverflow.com/questions/4831050/listing-contents-of-an-r-data-file-without-loading">listing contents of an R data file without loading</a></p>
  
  <p>In that case, the solution offered was:</p>
  
  <pre><code>attach(filename)
  ls(pos = 2)
  detach()
  </code></pre>
  
  <p>If there are naming conflicts between objects in the file and those in the global environment, this warning appears:
  <code>The following object(s) are masked _by_ '.GlobalEnv':</code></p>
  
  <p>I tried creating a new environment, but I cannot seem to attach into that.
  For instance, this produces the same error:</p>
  
  <pre><code>lsfile   &lt;- function(filename){
    tmpEnv &lt;- new.env()
    evalq(attach(filename), envir = tmpEnv)
    tmpls &lt;- ls(pos = 2)
    detach()
    return(tmpls)
  }
  lsfile(filename)
  </code></pre>
  
  <p>Maybe I've made a mess of things with <code>evalq</code> (or <code>eval</code>).  Is there some other way to avoid the naming conflict?</p>
  
  <p>2: If I want to access an object - if there are no naming conflicts, I can just work with the one from the .rdat file, or copy it to a new one.  If there are conflicts, how does one access the object in the file's namespace?</p>
  
  <p>For instance, if my file is "sample.rdat", and the object is surveyData, and a surveyData object already exists in the global environment, then how can I access the one from the <code>file:sample.rdat</code> namespace?</p>
  
  <p>I currently solve this problem by loading everything into a temporary environment, and then copy out what's needed, but this is inefficient.</p>