Merge branch 'master' of github.com:hadley/r4ds
This commit is contained in:
commit
64608d305b
|
@ -146,7 +146,7 @@ Compared to the original, this code is easier to understand and we've eliminated
|
|||
```
|
||||
|
||||
1. Read the [complete lyrics](https://en.wikipedia.org/wiki/Little_Bunny_Foo_Foo)
|
||||
to "Little Bunny Foo". There's a lot of duplication in this song.
|
||||
to "Little Bunny Foo Foo". There's a lot of duplication in this song.
|
||||
Extend the initial piping example to recreate the complete song, and use
|
||||
functions to reduce the duplication.
|
||||
|
||||
|
@ -279,6 +279,14 @@ if (NA) {}
|
|||
|
||||
You can use `||` (or) and `&&` (and) to combine multiple logical expressions. These operators are "short-circuiting": as soon as `||` sees the first `TRUE` it returns `TRUE` without computing anything else. As soon as `&&` sees the first `FALSE` it returns `FALSE`. You should never use `|` or `&` in an `if` statement: these are vectorised operations that apply to multiple values. If you do have a logical vector, you can use `any()` or `all()` to collapse it to a single value.
|
||||
|
||||
You can enforce this more-strictly by using the `identical()` function, which returns either a single `TRUE` or a single `FALSE`. One thing to watch out for is that *you* have to be more strict when specifying integers:
|
||||
|
||||
```{r}
|
||||
if (i == 0){}
|
||||
|
||||
if (identical(i, 0L)){}
|
||||
```
|
||||
|
||||
### Multiple conditions
|
||||
|
||||
You can chain multiple if statements together:
|
||||
|
|
Loading…
Reference in New Issue