When demonstrating how to write the function to convert the temperature, go
slowly and demonstrate how to do it in steps in RStudio. For instance, start by
taking one of the numeric examples, replace the number by the variable temp
,
explain that temp
doesn't exist in the global environment, and that we will be
creating it by enclosing it into a function:
(temp - 32) * 5/9
-
function(temp) { (temp - 32) * 5/9 }
- Demonstrate default values: show how convert_fahr() doesn't work.
- Change function to have default value for the temperature (e.g.,
temp = 0
andto = "celcius"
, and show how nowconvert_fahr()
works. - Use this to expand on using
match.arg
coming up.
- Demonstrate scoping:
- Show that there is no variable
to
,temp
orres
in the global environment. - Then assign a value to the variable
to
orres
and show that it doesn't affect the behavior of the function.
- Show that there is no variable