50 likes | 200 Views
An introduction to R (cont). Ståle Nygård ( staaln@math.uio.mo ) Department of Mathematics, University of Oslo 23.11.2007 Course in Statistical methods and bioinformatics for the analysis of microarray data. Packages in R. All R functions and datasets are stored in packages .
E N D
An introduction to R (cont) Ståle Nygård (staaln@math.uio.mo) Department of Mathematics, University of Oslo 23.11.2007 Course in Statistical methods and bioinformatics for the analysis of microarray data
Packages in R • All R functions and datasets are stored in packages. • Some packages are standard, the rest has to be installed and loaded. • A package is installed (or updated) by • Going to Install package(s) in the R menu line or • Typing > install.packages() (or > update.packages() ) • To see which packages are installed at your site, issue the command > library() with no arguments. • Only when a package is loaded are its contents available.To load a particular package (e.g. the bioconductor affy package), use a command like > library(affy) • To see which packages are currently loaded, use > search() to display the search list.
Contributed packages and CRAN • There are hundreds of contributed packages for R, written by many different authors. • Some of these packages implement specialized statistical methods, others give access to data or hardware, and others are designed to complement textbooks. • Some (the recommended packages) are distributed with every binary distribution of R. Most are available for download from CRAN (http://CRAN.R-project.org/ and its mirrors), and other repositories such as Bioconductor (http://www.bioconductor.org/).
Working directories • To set the working directory to e.g. C:/microarray, type > setwd(”C:/microarray”) (If you have a file microdata.txt stored in C:/microarray, you can then load the file by e.g. typing data=read.table(”microdata.txt”)) • To find your current directory, type > getwd() • It is recommended that you should use separate working directories for different analyses conducted with R
Workspaces • During an R session, objects (variables, functions etc.) are created and stored by name. The collection of objects currently stored is called the workspace. The R command > objects() (alternatively, ls()) can be used to display the names of (most of) the objects which are currently stored within R. • At the end of each R session you are given the opportunity to save the workspace. If you indicate that you want to do this, the objects are written to a file called .RData in the current directory, and the command lines used in the session are saved to a file called .Rhistory. • When R is started at later time from the same directory it reloads the workspace and the associated commands history is reloaded from this file.