Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding code example to "Automatic return" #374

Open
jnvaughn opened this issue Jun 19, 2018 · 2 comments
Open

adding code example to "Automatic return" #374

jnvaughn opened this issue Jun 19, 2018 · 2 comments

Comments

@jnvaughn
Copy link

@jnvaughn jnvaughn commented Jun 19, 2018

Would be nice to see something like this examples associated with the side note:

So, an alternative way of writing the previous function would be:
fahrenheit_to_kelvin <- function(temp_F) {
((temp_F - 32) * (5 / 9)) + 273.15
}

@katrinleinweber
Copy link
Contributor

@katrinleinweber katrinleinweber commented Jun 19, 2018

Good point, but I wonder whether we can turn that side note into something even more useful ;-) How about a challenge that leads learners to the solution you posted above. They would have to figure out then, that the intermediate temp_K assignment can be removed as well. What do you think?

Either way: do you want to start a PR about this against 02-func-R.Rmd? Either with your initial suggestion, or the challenge idea?

Loading

@engal
Copy link

@engal engal commented Jun 2, 2019

I'm curious whether it's actually worth the time to make this point in the episode. I've found that some people familiar with other languages before learning R can find R code using automatic returns somewhat unintuitive. I think part of this is because functions without return statements can look like functions that are supposed to be modifying objects in place (which rarely happens in R, data.tables being the main exception I've encountered, but does happen in other languages).

Since there is no functional difference between an automatic return and using a return statement , might it be simpler to leave out the note about automatic returns (or just avoid spending additional time)? I think the main counterargument would be that it could help learners when they encounter other peoples' code with automatic returns, but this seems like a marginal gain for people trying to initially get started with R.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants