Function arg tweaks

This commit is contained in:
hadley 2016-08-10 15:56:09 -05:00
parent 93a23b3f28
commit 9398e03ddf
1 changed files with 3 additions and 3 deletions

View File

@ -446,7 +446,7 @@ if (y < 20) {
## Function arguments ## Function arguments
The arguments to a function typically fall into two broad sets: one set supplies the data to compute on, and the other supplies arguments that control the details of the computation. For example: The arguments to a function typically fall into two broad sets: one set supplies the __data__ to compute on, and the other supplies arguments that control the __details__ of the computation. For example:
* In `log()`, the data is `x`, and the detail is the `base` of the logarithm. * In `log()`, the data is `x`, and the detail is the `base` of the logarithm.
@ -471,12 +471,12 @@ mean_ci <- function(x, conf = 0.95) {
x <- runif(100) x <- runif(100)
mean_ci(x) mean_ci(x)
mean_ci(x, 0.99) mean_ci(x, conf = 0.99)
``` ```
The default value should almost always be the most common value. The few exceptions are to do with safety. For example, it makes sense for `na.rm` to default to `FALSE` because missing values are important. Even though `na.rm = TRUE` is what you usually put in your code, it's a bad idea to silently ignore missing values by default. The default value should almost always be the most common value. The few exceptions are to do with safety. For example, it makes sense for `na.rm` to default to `FALSE` because missing values are important. Even though `na.rm = TRUE` is what you usually put in your code, it's a bad idea to silently ignore missing values by default.
When you call a function, typically you can omit the names for the data arguments (because they are used so commonly). If you override the default value of a detail argument, you should use the full name: When you call a function, you typically omit the names of the data arguments (because they are used so commonly). If you override the default value of a detail argument, you should use the full name:
```{r, eval = FALSE} ```{r, eval = FALSE}
# Good # Good