Hi Michael,
R returns the result of the last evaluated expression by default:
```
add_2 <- function(x) {
x + 2L
}
```
is the same as and preferred over
```
add_2_return <- function(x) {
out <- x + 2L
return(out)
}
```
In the idiomatic use of R, one uses explicit `return` when one wants to
Dénes, thank you for the guidance - which is well-taken.
Your side note raises an interesting question: I find the piping %>%
operator readable. Is there any downside to it? Or is the side note meant
to tell me to drop the last: "%>% `[`"?
Thank you,
==
Michael Lachanski
PhD Student in Demograp
Hi Michael,
Note that you have to be very careful when using by-reference operations
in data.table (see `?data.table::set`), especially in a functional
programming approach. In your function, you avoid this problem by
calling `data.table(A)` which makes a copy of A even if it is already a
dat
Às 06:50 de 31/12/2022, Michael Lachanski escreveu:
Hello,
I am trying to make a habit of "functionalizing" all of my code as
recommended by Hadley Wickham. I have found it surprisingly difficult to do
so because several intermediate features from data.table break or give
unexpected results usin
4 matches
Mail list logo