R in 3 Months Week 7 (Functions)

Functions

What is one function you can imagine creating for your own use?

Agenda

  1. Housekeeping

  2. Questions on Tidy Data

  3. Factors

  4. Functions

  5. Next Week

Housekeeping

Remaining Weeks

  • Week 8: Advanced Data Wrangling, Part 3 (Data Merging and Exporting Data)

  • Week 9: Advanced Data Viz, Part 1 (Highlighting and Decluttering)

  • Week 10: Catch-Up Week

  • Week 11: Advanced Data Viz, Part 2 (Explaining and Making Your Viz Sparkle)

  • Week 12: Advanced Quarto

  • Week 13: Wrap Up

Questions on Tidy Data?

Factors

In gss_cats, partyid is shown to be of the type . Can you refresh my memory on this type and where it is used?

Functions

Question on Function Arguments

I’m seeing a difference in the syntax used in the main video vs the solution video and am wondering if you can please explain the difference. In the main video, you use separate_longer_delim(cols = activities,... but the solution video uses separate_longer_delim(partyid,... without the use of cols =.

Advanced Functions

Assessment break

Why does the following R code execute without throwing an error?

calc <- function(a, b = stop("b is missing!")) {
  a * 2
}
calc(4)
  1. R checks default arguments before running the function, but skips any errors.

  2. R automatically ignores stop() in default arguments.

  3. R only evaluates arguments when they are used. Since b is never used in the function, stop() is never called.

  4. R automatically sets b to NULL when it is not provided.

Assessment break

Why does the following R code execute without throwing an error?

calc <- function(a, b = stop("b is missing!")) {
  a * 2
}
calc(4)
  1. R checks default arguments before running the function, but skips any errors.

  2. R automatically ignores stop() in default arguments.

  3. R only evaluates arguments when they are used. Since b is never used in the function, stop() is never called.

  4. R automatically sets b to NULL when it is not provided.

Next Week

  • Course lessons cover data merging and data exporting

  • Project assignment is to tidy your data with the various functions you have learned