Merge pull request #64 from ijlyttle/patch-2

Functions.Rmd: some proposed words on identical()
This commit is contained in:
Hadley Wickham 2016-03-10 08:33:24 -06:00
commit 97948370fe
1 changed files with 8 additions and 0 deletions

View File

@ -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: