liveBook · Manning

Function argument

As explained in Statistics Slam Dunk

A function argument is an input value supplied to a function when it is invoked.

A function argument is an input value supplied inside a function call. Arguments tell R what data or values a function should use before it produces a return value. section 13.7

When working with function arguments:

  • Place one or more inputs inside parentheses, separating multiple arguments with commas. section 13.7
  • Match the required arguments to the function’s expected inputs; omitting one can produce an error. section 13.7

Supplying arguments to a custom function

The custom gini.est() function requires a, b, and c. Calling gini.est(.05, .18) fails because c is missing; calling gini.est(.05, .18, .44) returns 0.522. section 13.7

r_to_rsquared <- function(r) {
  rsquared <- r^2
  return(rsquared)
}

See a user-defined function that accepts r as its argument and returns its squared value. section 13.7

How Statistics Slam Dunk covers it

How deep it goes
Defines arguments, distinguishes them from function bodies and return values, and demonstrates a missing-argument error.
Examples
Uses pivot_wider(), r_to_rsquared(), and gini.est() calls to show supplied inputs, outputs, and missing arguments.
What you can do after
Apply R functions by supplying required inputs and interpreting their returned values.
How it connects
Connects arguments with functions, parameters, function bodies, return values, and user-defined functions.

Also explained in

Compare how 5 books explain function argument →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.