User Tools

Site Tools


Working Directory


> getwd()
[1] "/home/paul/research"
> setwd("Bayes")
> getwd()
[1] "/home/paul/research/Bayes"

Saving Workspace

> save.image()

Command History

> history()             # Default 25
> history(100)          # Show 100 most recent lines of history
> history(Inf)          # Show entire saved history

Saving the Result of the Previous Command

> aVeryLongRunningFunction()     # Oops! Forgot to save the result!
[1] 147.6549
> x <- .Last.value               # Capture the result now
> x
[1] 147.6549

Displaying the Search Path

> search()

Gives a list of attached packages (see library), and R objects, usually data.frames.

Load and attach packages


library and require load and attach add-on packages.
NOTE: no quote on package name.


Built-in Datasets

Find out available data set.


Choose a specific data set from a specific package name.

> data(dsname, package="pkgname")
> require(graphics)
> plot(pressure, xlab = "Temperature (deg C)",
     ylab = "Pressure (mm of Hg)",
     main = "pressure data: Vapor Pressure of Mercury")
> plot(faithful, xlab = "eruptions",
     ylab = "waiting",
     main = "old faithful erruption and waiting ratio")

> data(Cars93, package="MASS") 
> data(package="pkgname") 

List of Installed Packages


Installing Packages

> install.packages("packagename")

Running a Script

> source("myScript.R")
b/r_cookbook/navigating.txt · Last modified: 2020/03/09 19:16 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki