Re: [R] Functional Programming Problem Using purr and R's data.table shift function

2023-01-03 Thread Dénes Tóth
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

Re: [R] Functional Programming Problem Using purr and R's data.table shift function

2023-01-02 Thread Michael Lachanski
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

Re: [R] Functional Programming Problem Using purr and R's data.table shift function

2022-12-31 Thread Dénes Tóth
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

Re: [R] Functional Programming Problem Using purr and R's data.table shift function

2022-12-31 Thread Rui Barradas
À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

[R] Functional Programming Problem Using purr and R's data.table shift function

2022-12-31 Thread Michael Lachanski
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 using purrr and its data.table adaptation, tidytable.