You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Start with much simpler functions: e.g. sum two values, print arguments, etc. (with zero, one, two, ... arguments)
Address basic scoping (see below) and the role of return() early on, on those simple functions
Scoping can be problematic in R (a mistyped name can be found in a parent environment), and is at the same time one of the main arguments for using functions, so it should take more than a note.
Which part of the content does your suggestion apply to?
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.
How could the content be improved?
Ch. 10. Functions Explained starts with examples of functions (
fahr_to_kelvin
andkelvin_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 thatreturn()
can be left out, and scoping rules.I'd suggest:
return()
early on, on those simple functionsR
(a mistyped name can be found in a parent environment), and is at the same time one of the main arguments for using functions, so it should take more than a note.Which part of the content does your suggestion apply to?
https://swcarpentry.github.io/r-novice-gapminder/10-functions.html
The text was updated successfully, but these errors were encountered: