From 51f8c2d8b52c474bd630131156047314b6d93918 Mon Sep 17 00:00:00 2001 From: hadley Date: Tue, 19 Jul 2016 08:11:08 -0500 Subject: [PATCH] Scatter around a few more explanations of :: --- relational-data.Rmd | 2 ++ transform.Rmd | 2 ++ visualize.Rmd | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/relational-data.Rmd b/relational-data.Rmd index 3ea290f..5174052 100644 --- a/relational-data.Rmd +++ b/relational-data.Rmd @@ -27,6 +27,8 @@ library(nycflights13) library(dplyr) ``` +We'll also use the `str_c()` function from stringr, but rather than loading the complete package just to access this one function, we'll use it as `stringr::str_c()`. + ## nycflights13 {#nycflights13-relational} You can use the nycflights13 package to learn about relational data. nycflights13 contains four data frames that are related to the `flights` table that you used in Data Transformation: diff --git a/transform.Rmd b/transform.Rmd index 70efc96..24aa5e0 100644 --- a/transform.Rmd +++ b/transform.Rmd @@ -140,6 +140,8 @@ near(sqrt(2) ^ 2, 2) near(1 / 49 * 49, 1) ``` +(Remember that we use `::` to explicit about where a function lives. If dplyr is installed, `dplyr::near()` will always work. If you want to use the shorter `near()`, you need to make sure you have loaded dplyr with `library(dplyr)`.) + ### Logical operators Multiple arguments to `filter()` are combined with "and": every expression must be true in order for a row to be included in the output. For other types of combinations, you'll need to use Boolean operators yourself: diff --git a/visualize.Rmd b/visualize.Rmd index b8aa925..d33e268 100644 --- a/visualize.Rmd +++ b/visualize.Rmd @@ -7,7 +7,7 @@ This chapter will teach you how to visualize your data with R and ggplot2. R con ## Prerequisites -To access the datasets, help pages, and functions that we will use in this chapter, load ggplot2. We'll also load tibble, which you'll learn about later. It improves the default printing of datasets. +To access the datasets, help pages, and functions that we will use in this chapter, load ggplot2 using the `library()` function. We'll also load tibble, which you'll learn about later. It improves the default printing of datasets. ```{r setup} library(ggplot2) @@ -23,6 +23,8 @@ library(ggplot2) You only need to install a package once, but you need to reload it every time you start a new session. +If we need to be explicit about where a function (or dataset) comes from, we'll use the special form `package::function()`. For example, `ggplot2::ggplot()` tells you explicitly that we're using the `ggplot()` function from the ggplot2 package. + ## A graphing template Let's use our first graph to answer a question: Do cars with big engines use more fuel than cars with small engines? You probably already have an answer, but try to make your answer precise. What does the relationship between engine size and fuel efficiency look like? Is it positive? Negative? Linear? Nonlinear?