From 9398e03ddf53d1952f19d2508b6a95820a5e6b23 Mon Sep 17 00:00:00 2001 From: hadley Date: Wed, 10 Aug 2016 15:56:09 -0500 Subject: [PATCH] Function arg tweaks --- functions.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions.Rmd b/functions.Rmd index ce77dcd..8c12c51 100644 --- a/functions.Rmd +++ b/functions.Rmd @@ -446,7 +446,7 @@ if (y < 20) { ## 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. @@ -471,12 +471,12 @@ mean_ci <- function(x, conf = 0.95) { x <- runif(100) 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. -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} # Good