Functions

Why Use Functions?

  1. Explain how functions are analogous to data structures in terms of the “nouns” versus “verbs” of programming.
  2. Give situations when a block of code should be turned into a function.

Function Syntax in R

  1. State the syntax for defining a function in R using function().
  2. Given a block of code to turn into a function, produce a function using function().
  3. State the names for the inputs and outputs of a function in R.

Named Arguments and Default Values

  1. Include named arguments in a function to pass desired inputs into the function.
  2. State and use the appropriate operator to bind a function argument when calling a function.
  3. Include named arguments with default values in a function.
  4. Call a function using named and unnamed arguments.
  5. Determine the output of a given function with named or unnamed arguments.
  6. Use stopifnot() to check function arguments for desired / necessary characteristics.

Function Environments and Interfacing with Functions

  1. Explain the difference between a global environment and local / internal environment in R.
  2. Describe the rules for how the interval environment of a function interfaces with the global environment.
  3. Given a block of code including a function definition, describe the values stored in the global and internal environments before, during, and after a function call.
  4. State the best-practices for interfacing with a function.

Gradient / Steepest Descent

  1. Explain how to find the minima / maxima of a smooth function of a single variable using calculus.
  2. Describe the procedure for using gradient descent to find the minima of a function, and relate this to the analogy of walking down a hill when you can only see one step ahead of you at any given time.
  3. Explain why gradient descent may not find the global minimum of a function when multiple minima exist, and relate this to the hill analogy.
  4. Explain the rationale for the stopping criteria for gradient descent.
  5. Implement gradient descent, or some portion of the gradient descent algorithm, as a function in R.