Chapter 1. R Basics
This chapter covers the basics: installing and using packages and loading data.
If you want to get started quickly, most of the recipes in this book require the ggplot2 and gcookbook packages to be installed on your computer. To do this, run:
install.packages(c("ggplot2","gcookbook"))
Then, in each R session, before running the examples in this book, you can load them with:
library(ggplot2)library(gcookbook)
Note
Appendix A provides an introduction to the ggplot2 graphing package, for readers who are not already familiar with its use.
Packages in R are collections of functions and/or data that are bundled up for easy distribution, and installing a package will extend the functionality of R on your computer. If an R user creates a package and thinks that it might be useful for others, that user can distribute it through a package repository. The primary repository for distributing R packages is called CRAN (the Comprehensive R Archive Network), but there are others, such as Bioconductor and Omegahat.
Installing a Package
Problem
You want to install a package from CRAN.
Solution
Use install.packages() and
give it the name of the package you want to install. To install ggplot2,
run:
install.packages("ggplot2")
At this point you may be prompted to select a download mirror. You can either choose the one nearest to you, or, if you want to make sure you have the most up-to-date version of your package, choose the Austria site, which is the primary CRAN server.
Discussion
When you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access