swcarpentry / r-novice-gapminder

R for Reproducible Scientific Analysis

Home Page:http://swcarpentry.github.io/r-novice-gapminder/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lesson Contribution - return function

Talishask opened this issue · comments

I'm a member of The Carpentries Core Team and I'm submitting this issue on behalf of another member of the community. In most cases, I won't be able to follow up or provide more details other than what I'm providing below.


In this lesson (https://swcarpentry.github.io/r-novice-gapminder/10-functions/index.html), there is a mention of the return function. I think that more information can be included to explain the return function:

  1. If you do not include it will not print the final variable to the console
  2. The returned variable will cause the function to stop.

Thanks for passing this along, @Talishask . For now, I think the explanation of the return() function is sufficient. I'll also note that the variable value is printed even without the return() statement. e.g.

tiny_fun <- function(x) {
  x * 2
}
tiny_fun(3)
# [1] 6