Built-in Data Files

There are many built-in data sets within the base package of R. You can see their names by typing

data()

You can read the documentation for a particular data set with the usual query:

?lynx

Many of the contributed packages contain data sets, and you can view their names using the try function. This evaluates an expression and traps any errors that occur during the evaluation. The try function establishes a handler for errors that uses the default error handling protocol:

try(data(package="spatstat"));Sys.sleep(3)
try(data(package="spdep"));Sys.sleep(3)
try(data(package="MASS"))

Built-in data files can be attached in the normal way; then the variables within them accessed by their names:

attach(OrchardSprays)
decrease

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.