swcarpentry / r-novice-gapminder

R for Reproducible Scientific Analysis
http://swcarpentry.github.io/r-novice-gapminder/
Other
164 stars 537 forks source link

Smoother introduction to functions? #865

Open martinherrerias opened 1 year ago

martinherrerias commented 1 year ago

How could the content be improved?

Ch. 10. Functions Explained starts with examples of functions (fahr_to_kelvin and kelvin_to_celsius) that are clunky to type (draw attention away from the matter) and not rich enough to explain general function syntax and scoping. Then, halfway down the lesson, and while working on a more complicated function, there's suddenly: multiple-arguments, default values, the fact that return() can be left out, and scoping rules.

I'd suggest:

Which part of the content does your suggestion apply to?

https://swcarpentry.github.io/r-novice-gapminder/10-functions.html

Malberten commented 1 year ago

On the point about the return() statement (not sure if this deserves its own issue, but it fits here nicely):

Further down it is explained, that "R will automatically return the results of whatever command is executed on the last line of the function" (https://swcarpentry.github.io/r-novice-gapminder/10-functions.html#more-on-combining-functions). I think this statement is misleading, since you could think that in the example above you can just remove the return() line and it works the same. But you would also need to omit the "gdp<-" in the line before.

So I would suggest to rather include to equivalent examples, one with a return() statement, and one without.

Apart from that I fully agree with the issues raised by @martinherrerias.

scottpctseng commented 3 months ago

As a PhD student in Europe with Asian heritage, I especially agree with this issue. Fahrenheit is rarely used in Asia nor in Europe, not to mention Kelvin (more useful in science AFAIK). Converting between them makes things even more complex. Since Carpentries aims to relieve cognitive load, I strongly believe that there are better choices for this episode. Celsius_to_Kelvin seems to be a more suitable choice to me. After all, the goal is only to learn the usage and structure of Function in R.

naupaka commented 2 months ago

I agree with the comments here about cognitive complexity, but changing this out would represent a pretty substantial overhaul of the whole lesson. What do you think @matthieu-bruneaux @skanwal?