Workspace management

Managing workspace packages.


Installing a package

From inside the workspace.

install.packages("knitr")

From outside any R session Download from CRAN, by ex. http://cran.r-project.org/web/packages/knitr/index.html

R CMD INSTALL knitr


Loading a package

Load a package, with or without the localisation to be used.

library("Biobase", lib.loc = "/home/chernan/R/i686-pc-linux-gnu-library/2.15")

List loaded packages

Get a global view of the current session. In reproducible research, this information is important to keep after a data analysis, in order to be able to re-set the same environment.

sessionInfo()
## R version 2.15.2 (2012-10-26)
## Platform: i686-pc-linux-gnu (32-bit)
## 
## locale:
##  [1] LC_CTYPE=fr_CH.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=fr_CH.UTF-8        LC_COLLATE=fr_CH.UTF-8    
##  [5] LC_MONETARY=fr_CH.UTF-8    LC_MESSAGES=fr_CH.UTF-8   
##  [7] LC_PAPER=C                 LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=fr_CH.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] datasets  stats     graphics  grDevices utils     methods   base     
## 
## other attached packages:
## [1] biomaRt_2.14.0  ggplot2_0.9.3.1 markdown_0.5.4  knitr_1.1      
## 
## loaded via a namespace (and not attached):
##  [1] colorspace_1.2-1   dichromat_2.0-0    digest_0.6.3      
##  [4] evaluate_0.4.7     formatR_0.7        grid_2.15.2       
##  [7] gtable_0.1.2       KernSmooth_2.23-9  labeling_0.1      
## [10] MASS_7.3-23        munsell_0.4        plyr_1.8          
## [13] proto_0.3-10       RColorBrewer_1.0-5 RCurl_1.95-3      
## [16] reshape2_1.2.2     scales_0.2.3       stringr_0.6.2     
## [19] tools_2.15.2       XML_3.95-0.1

Get the list of all currently loaded packages, and a few information on them.

installed.packages()[.packages(), ]
##           Package     LibPath                                         
## biomaRt   "biomaRt"   "/home/chernan/R/i686-pc-linux-gnu-library/2.15"
## ggplot2   "ggplot2"   "/home/chernan/R/i686-pc-linux-gnu-library/2.15"
## markdown  "markdown"  "/home/chernan/R/i686-pc-linux-gnu-library/2.15"
## knitr     "knitr"     "/home/chernan/R/i686-pc-linux-gnu-library/2.15"
## datasets  "datasets"  "/usr/lib/R/library"                            
## stats     "stats"     "/usr/lib/R/library"                            
## graphics  "graphics"  "/usr/lib/R/library"                            
## grDevices "grDevices" "/usr/lib/R/library"                            
## utils     "utils"     "/usr/lib/R/library"                            
## methods   "methods"   "/usr/lib/R/library"                            
## base      "base"      "/usr/lib/R/library"                            
##           Version   Priority Depends                      
## biomaRt   "2.14.0"  NA       "methods"                    
## ggplot2   "0.9.3.1" NA       "R (>= 2.14), stats, methods"
## markdown  "0.5.4"   NA       "R (>= 2.11.1)"              
## knitr     "1.1"     NA       "R (>= 2.14.1)"              
## datasets  "2.15.2"  "base"   NA                           
## stats     "2.15.2"  "base"   NA                           
## graphics  "2.15.2"  "base"   NA                           
## grDevices "2.15.2"  "base"   NA                           
## utils     "2.15.2"  "base"   NA                           
## methods   "2.15.2"  "base"   NA                           
## base      "2.15.2"  "base"   NA                           
##           Imports                                                                                       
## biomaRt   "utils, XML, RCurl"                                                                           
## ggplot2   "plyr (>= 1.7.1), digest, grid, gtable (>= 0.1.1), reshape2,\nscales (>= 0.2.3), proto, MASS" 
## markdown  NA                                                                                            
## knitr     "evaluate (>= 0.4.3), digest, formatR (>= 0.3-4), markdown (>=\n0.4), stringr (>= 0.6), tools"
## datasets  NA                                                                                            
## stats     NA                                                                                            
## graphics  "grDevices"                                                                                   
## grDevices NA                                                                                            
## utils     NA                                                                                            
## methods   "utils"                                                                                       
## base      NA                                                                                            
##           LinkingTo
## biomaRt   NA       
## ggplot2   NA       
## markdown  NA       
## knitr     NA       
## datasets  NA       
## stats     NA       
## graphics  NA       
## grDevices NA       
## utils     NA       
## methods   NA       
## base      NA       
##           Suggests                                                                     
## biomaRt   "annotate"                                                                   
## ggplot2   "quantreg, Hmisc, mapproj, maps, hexbin, maptools, multcomp,\nnlme, testthat"
## markdown  "RCurl"                                                                      
## knitr     "testthat, rgl, codetools, R2SWF (>= 0.4), XML, RCurl, Rcpp\n(>= 0.10.0)"    
## datasets  NA                                                                           
## stats     NA                                                                           
## graphics  NA                                                                           
## grDevices NA                                                                           
## utils     NA                                                                           
## methods   NA                                                                           
## base      NA                                                                           
##           Enhances OS_type License            Built   
## biomaRt   NA       NA      "Artistic-2.0"     "2.15.2"
## ggplot2   "sp"     NA      "GPL-2"            "2.15.2"
## markdown  NA       NA      "GPL-3"            "2.15.2"
## knitr     NA       NA      "GPL"              "2.15.2"
## datasets  NA       NA      "Part of R 2.15.2" "2.15.2"
## stats     NA       NA      "Part of R 2.15.2" "2.15.2"
## graphics  NA       NA      "Part of R 2.15.2" "2.15.2"
## grDevices NA       NA      "Part of R 2.15.2" "2.15.2"
## utils     NA       NA      "Part of R 2.15.2" "2.15.2"
## methods   NA       NA      "Part of R 2.15.2" "2.15.2"
## base      NA       NA      "Part of R 2.15.2" "2.15.2"

Save/Load

Save the list of loaded packages in a file, and load packages from this file.

  • Write the list of loaded packages in a file
instPackages <- installed.packages()[.packages(), ]
write.table(instPackages, "loadedPackages.txt", quote = TRUE)
  • Load packages from a file
packagesToLoad <- read.table("loadedPackages.txt", header = TRUE, stringsAsFactors = FALSE)
apply(packagesToLoad, 1, FUN = function(aLib) {
    library(package = aLib["Package"], lib.loc = aLib["LibPath"], character.only = TRUE)
})

Detach a package

Detach a package

detach("package:affy", unload = TRUE)

Creative Commons License
This work by Celine Hernandez is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.