title: detach all packages while working in R
body: <p>While working to solve another problem I got this problem:</p>
  
  <p>I can remove all  R objects by:</p>
  
  <pre><code>rm(list = ls(all = TRUE))
  </code></pre>
  
  <p>Is there equivalent command that can detach installed packages during working session?</p>
  
  <pre><code>&gt; sessionInfo()
  R version 2.12.2 (2011-02-25)
  Platform: i386-pc-mingw32/i386 (32-bit)
  
  locale:
  [1] LC_COLLATE=English_United States.1252 
  [2] LC_CTYPE=English_United States.1252   
  [3] LC_MONETARY=English_United States.1252
  [4] LC_NUMERIC=C                          
  [5] LC_TIME=English_United States.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base 
  </code></pre>
  
  <blockquote>
    <p>require(ggplot2)</p>
  </blockquote>
  
  <pre><code>Loading required package: ggplot2
  Loading required package: reshape
  Loading required package: plyr
  
  Attaching package: 'reshape'
  
  The following object(s) are masked from 'package:plyr':
  
      round_any
  
  Loading required package: grid
  Loading required package: proto
  </code></pre>
  
  <blockquote>
    <p>sessionInfo()</p>
  </blockquote>
  
  <pre><code>R version 2.12.2 (2011-02-25)
  Platform: i386-pc-mingw32/i386 (32-bit)
  
  locale:
  [1] LC_COLLATE=English_United States.1252 
  [2] LC_CTYPE=English_United States.1252   
  [3] LC_MONETARY=English_United States.1252
  [4] LC_NUMERIC=C                          
  [5] LC_TIME=English_United States.1252    
  
  attached base packages:
  [1] grid      stats     graphics  grDevices utils     datasets  methods  
  [8] base     
  
  other attached packages:
  [1] ggplot2_0.8.9 proto_0.3-9.1 reshape_0.8.4 plyr_1.4 
  </code></pre>
  
  <p>I tried this way, although even it worked in not a global solution :</p>
  
  <pre><code>pkg &lt;- c("package:ggplot2_0.8.9", "package:proto_0.3-9.1", "package:reshape_0.8.4",  "package:plyr_1.4")
  
   detach(pkg, character.only = TRUE)
  
  Error in detach(pkg, character.only = TRUE) : invalid 'name' argument
  In addition: Warning message:
  In if (is.na(pos)) stop("invalid 'name' argument") :
    the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p>What I am loking for is something global like:</p>
  
  <pre><code>  rm(list = ls(all = TRUE))
  </code></pre>
  
  <p>for objects, expect it would not remove attached base packages</p>
  
  <p>thanks; </p>