Appendix B

The r fordummies Package

You can find all of the example code of this book in an R package called rfordummies. You can install this package directly from CRAN and then use the package to view the code and run the examples in the book.

Using rfordummies

You install the rfordummies package directly from CRAN using the function install.packages(). If you add the argument dependencies = TRUE, you automatically install all the packages mentioned in the book, like this:

> install.packages("rfordummies", dependencies = TRUE)

You load the package by using the function library():

> library("rfordummies")

You can view the table of contents of the book by using the function toc():

> toc()

To view the chapter code for a specific chapter, use the function chxx(), where xx means the chapter number. For example, to view the code for Chapters 2 and 13, enter these functions:

> ch2()

> ch13()

To run the examples from a specific chapter, use the example() function. This function runs all the example code given on a certain help page. So to run all examples from Chapter 3, try:

> example("ch3", package = "rfordummies")

You can also find the data for the periodic table of elements (see Chapter 12) in a data frame called elements:

> ?elements

> head(elements)

For more information, check the help page ?rfordummies.

Get R For Dummies, 2nd Edition 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.