diff --git a/functions.Rmd b/functions.Rmd index d594cd5..f88e532 100644 --- a/functions.Rmd +++ b/functions.Rmd @@ -280,7 +280,7 @@ if (condition) { To get help on `if` you need to surround it in backticks: `` ?`if` ``. The help isn't particularly helpful if you're not already an experienced programmer, but at least you know how to get to it! -Here's a simple function that uses an if statement. The goal of this function is to return a logical vector describing whether or not each element of a vector is named. +Here's a simple function that uses an `if` statement. The goal of this function is to return a logical vector describing whether or not each element of a vector is named. ```{r} has_name <- function(x) { diff --git a/pipes.Rmd b/pipes.Rmd index 3a1fa95..1bfc9bb 100644 --- a/pipes.Rmd +++ b/pipes.Rmd @@ -131,7 +131,7 @@ foo_foo %>% bop(on = head) ``` -This is my favourite form, because it focusses on verbs, not nouns. You can read this series of function compositions like it's a set of imperative actions. Foo Foo hops, then scoops, then bops. The downside, of course, is that you need to be familiar with the pipe. If you've never seen `%>%` before, you'll have no idea what this code does. Fortunately, most people pick up the idea very quickly, so when you share you code with others who aren't familiar with the pipe, you can easily teach them. +This is my favourite form, because it focusses on verbs, not nouns. You can read this series of function compositions like it's a set of imperative actions. Foo Foo hops, then scoops, then bops. The downside, of course, is that you need to be familiar with the pipe. If you've never seen `%>%` before, you'll have no idea what this code does. Fortunately, most people pick up the idea very quickly, so when you share your code with others who aren't familiar with the pipe, you can easily teach them. The pipe works by performing a "lexical transformation": behind the scenes, magrittr reassembles the code in the pipe to a form that works by overwriting an intermediate object. When you run a pipe like the one above, magrittr does something like this: diff --git a/vectors.Rmd b/vectors.Rmd index f1a155b..3a3095e 100644 --- a/vectors.Rmd +++ b/vectors.Rmd @@ -48,7 +48,7 @@ Every vector has two key properties: length(x) ``` -Vectors can also contain arbitrary additional metadata in the form of attributes. These attributes are used to create __augmented vectors__ which build on additional behaviour. There are four important types of augmented vector: +Vectors can also contain arbitrary additional metadata in the form of attributes. These attributes are used to create __augmented vectors__ which build on additional behaviour. There are three important types of augmented vector: * Factors are built on top of integer vectors. * Dates and date-times are built on top of numeric vectors. @@ -194,7 +194,7 @@ There are two ways to convert, or coerce, one type of vector to another: Because explicit coercion is used relatively rarely, and is largely easy to understand, I'll focus on implicit coercion here. -You've already seen the most important type of implicit coercion: using a logical vector in a numeric context. In this case `TRUE` is converted to `1` and `FALSE` converted to 0. That means the sum of a logical vector is the number of trues, and the mean of a logical vector is the proportion of trues: +You've already seen the most important type of implicit coercion: using a logical vector in a numeric context. In this case `TRUE` is converted to `1` and `FALSE` converted to `0`. That means the sum of a logical vector is the number of trues, and the mean of a logical vector is the proportion of trues: ```{r} x <- sample(20, 100, replace = TRUE)