swcarpentry/r-novice-gapminder

Introduction to R and RStudio - introduction to functions

hareball90 opened this issue · 4 comments

In the Introduction to R and RStudio episode, mathematical functions are introduced. The Seeking Help episode talks about function help files. The next use of a function is then calling data.frame and write.csv at the beginning of the
Data Structures episode. Additional information on functions is then covered in the
Functions Explained episode.

When I used this material to run an informal session with colleagues, I struggled to follow the flow of how to introduce functions, as we went from a single input mathematical function, into documentation of a function, and then into a multiple argument functions and changing defaults. This happened without without talking about what a function was and what it did. The attendees also raised the following questions:

  • What is an argument?
  • Why are some arguments explicitly called when typing a function?

I found that the Data Capentry Introduction to R was useful, and re-introduced functions using this little excerpt.

To avoid adding or moving material, could I suggest the following.

In the description of mathematical functions the argument text could be amended to explain that an argument is an input into a function, and that the number of inputs alters according to the function (either being zero or multiple). This can then be mentioned when using getwd().

Then, when reading help files an example could be added to create another opportunity to talk about functions. I would suggest ?write.csv since this is one of the next functions used that requires arguments and altering defaults. A comment can then be made again about functions calling multiple arguments, and that the arguments can be assigned default values, and the benefit of explicitly calling arguments when using the function. (This then shouldn't intrude on the challenge at the end of the episode.)

Then, when write.csv is used at the beginning of Data Structures episode the function has been briefly seen before, and the need to use argument names can be enforced.

I think this would suitably complement the later episode where learners create their own functions.

Thank you.

Thanks, @HWilliams-PHE ! Want to open a PR with this change?

Hi @jcoliver and @HWilliams-PHE, I recently went through the material for R for Reproducible Scientific Analyses to study for my teaching demo and shared similar thoughts with @HWilliams-PHE.

I agree the leap from Seeking help to Data Structures is a little wide for absolute beginners and the flow is a tad awkward for reasons @HWilliams-PHE has detailed above.

Given that Data Structures seems to be a integral lesson recommended here in the Instructor Notes, I definitely think we can improve the flow but adding more baby steps between Seeking Help towards Data Structures.

I am happy to attempt a PR! Just flagging it here in! :)

  • In the description of mathematical functions the argument text could be amended to explain that an argument is an input into a function, and that the number of inputs alters according to the function (either being zero or multiple). This can then be mentioned when using getwd().

  • Then, when reading help files an example could be added to create another opportunity to talk about functions. I would suggest ?write.csv since this is one of the next functions used that requires arguments and altering defaults. A comment can then be made again about functions calling multiple arguments, and that the arguments can be assigned default values, and the benefit of explicitly calling arguments when using the function. (This then shouldn't intrude on the challenge at the end of the episode.)

  • Then, when write.csv is used at the beginning of Data Structures episode the function has been briefly seen before, and the need to use argument names can be enforced.

All done @jcoliver! Thanks for your suggestions @HWilliams-PHE! I will submit a PR now! Hope it helps The Carpentries Community :)

This was addressed by #787.

Thank you @HWilliams-PHE and @fontikar for your valuable help with this lesson!