Wednesday, June 25, 2014

Data analysis using R - R programming Tutorial ( Part 7 )


The workspace is where all the objects you create during a session are
When you close R you will be prompted to “Save workspace image?” If you
say yes, the next time you open R from the same working directory the
workspace will be restored. That is all of the objects you created during your
last session will still be available. Also see save.image().

Depending on what you are working on, it is usually wiser to write a script
and then run the entire script with each new session. This way you know
exactly what objects you have created; sometimes lingering objects can
cause errors in programs. If a particular object is very important then save it
to a file.
Managing the Workspace
- To list what variables you have created in the current session, ls()
- To see what libraries and dataframes are loaded, search()
- To see what libraries have been installed, library()
- To remove an object, rm(object names)
- To remove all objects, rm(list=ls())

The function options() sets several global options that affect how R
computes and displays results.
To look at the value of a single option, getOption("option name")
Options reset to the defaults with each new R session, even if you save the
For example suppose we want to change the maximum number of digits
printed from 7 (default) to 15.
> defaults <- options() # Save all default options
> getOption("digits")
[1] 7
> pi
[1] 3.141593
> options(digits=15) # Change to 15 digits
> pi
[1] 3.14159265358979
> options(defaults) # Restore all default options
> getOption("digits")
[1] 7