Merge branch 'master' of github.com:hadley/r4ds

This commit is contained in:
hadley 2016-07-15 15:51:02 -05:00
commit 864ac2761e
2 changed files with 5 additions and 5 deletions

View File

@ -115,7 +115,7 @@ x <- c(1:10, Inf)
rescale01(x)
```
Because we've extract the code into a function, we only need to make the fix in one place:
Because we've extracted the code into a function, we only need to make the fix in one place:
```{r}
rescale01 <- function(x) {
@ -125,7 +125,7 @@ rescale01 <- function(x) {
rescale01(x)
```
This is an important part of the "do no repeat yourself" (or DRY) principle. The more repitition you have in your code, the more places you need to remember to update when things change (and they always code!), and the more likely you are to create bugs over time.
This is an important part of the "do not repeat yourself" (or DRY) principle. The more repetition you have in your code, the more places you need to remember to update when things change (and they always could!), and the more likely you are to create bugs over time.
### Practice
@ -175,7 +175,7 @@ It's important to remember that functions are not just for the computer, but are
The name of a function is important. Ideally the name of your function will be short, but clearly evoke what the function does. However, it's hard to come up with concise names, and autocomplete makes it easy to type long names, so it's better to err on the side of clear descriptions, rather than short names.
Generally, function names should be verbs, and arguments should be nouns. There are some exceptions: nouns are ok if the function computes a very well known noun (i.e. `mean()` is better than `compute_mean()`), or accessing some property of an object (i.e. `coef()` is better than `get_coefficients()`). A good sign that a noun might be a better choice is if you're using a very broad verb like "get", "compute", "calculate", or determine. Use your best judgement and don't be afraid to rename a function if you later figure out a better name.
Generally, function names should be verbs, and arguments should be nouns. There are some exceptions: nouns are ok if the function computes a very well known noun (i.e. `mean()` is better than `compute_mean()`), or accessing some property of an object (i.e. `coef()` is better than `get_coefficients()`). A good sign that a noun might be a better choice is if you're using a very broad verb like "get", "compute", "calculate", or "determine". Use your best judgement and don't be afraid to rename a function if you figure out a better name later.
```{r, eval = FALSE}
# Too short

View File

@ -364,7 +364,7 @@ Note that the precedence of these operators is high, so you can write: `colou?r`
### Grouping and backreferences
You learned about parentheses earlier as a way to disambiguate complex expression. They do one other special thing: they also define numeric groups that you can refer to with _backreferences_, `\1`, `\2` etc.For example, the following regular expression finds all fruits that have a pair of letters that's repeated.
You learned about parentheses earlier as a way to disambiguate complex expression. They do one other special thing: they also define numeric groups that you can refer to with _backreferences_, `\1`, `\2` etc. For example, the following regular expression finds all fruits that have a pair of letters that's repeated.
```{r, cache = FALSE}
str_view(fruit, "(..)\\1", match = TRUE)
@ -602,7 +602,7 @@ sentences %>%
#### Exercises
1. Replace all `/`'s in a string with `\`'s.
1. Replace all `/`s in a string with `\`s.
### Splitting