
上QQ阅读APP看书,第一时间看更新
How to do it...
R makes installing additional packages simple:
- Launch the R interactive environment or, preferably, RStudio.
- Let's install ggplot2. Type the following command, and then press the Enter key:
install.packages("ggplot2")
Note that for the remainder of the book, it is assumed that, when we specify entering a line of text, it is implicitly followed by hitting the Return or Enter key on the keyboard
- You should now see text similar to the following as you scroll down the screen:
trying URL 'http://cran.rstudio.com/bin/macosx/contrib/3.0/
ggplot2_0.9.3.1.tgz'Content type 'application/x-gzip' length 2650041 bytes (2.5
Mb) opened URL ================================================== downloaded 2.5 Mb The downloaded binary packages are in /var/folders/db/z54jmrxn4y9bjtv8zn_1zlb00000gn/T//Rtmpw0N1dA/
downloaded_packages
- You might have noticed that you need to know the exact name, in this case, ggplot2, of the package you wish to install. Visit http://cran.us.r-project.org/web/packages/available_packages_by_name.html to make sure you have the correct name.
- RStudio provides a simpler mechanism to install packages. Open up RStudio if you haven't already done so.
- Go to Tools in the menu bar and select Install Packages .... A new window will pop up, as shown in the following screenshot:

- As soon as you start typing in the Packages field, RStudio will show you a list of possible packages. The autocomplete feature of this field simplifies the installation of libraries. Better yet, if there is a similarly named library that is related, or an earlier or newer version of the library with the same first few letters of the name, you will see it.
- Let's install a few more packages that we highly recommend. At the R prompt, type the following commands:
install.packages("lubridate") install.packages("plyr") install.packages("reshape2")
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files E-mailed directly to you.