Reputation: 2166
Is there a way to update deprecated functions in R automatically or perhaps write scripts in a way that makes updating deprecated functions easier. An example: I have scripts where summarise_each
from dplyr
is used many times:
library(dplyr)
mtcars %>% group_by(gear) %>% summarise_each(funs(mean), mpg)
`summarise_each()` is deprecated.
Use `summarise_all()`, `summarise_at()` or `summarise_if()` instead.
To map `funs` over a selection of variables, use `summarise_at()`
New format
mtcars %>% group_by(gear) %>% summarise_at(vars(mpg), funs(mean))
# A tibble: 3 x 2
gear mpg
<dbl> <dbl>
1 3 16.10667
2 4 24.53333
3 5 21.38000
Of course I know I can find and replace summarise_each
but in this example the vars
bit could be lots of different things. Perhaps the only way is the good old fashioned way but I want to check before I start manually editing everything.
Upvotes: 2
Views: 537
Reputation: 1234
I think it is very important to consider the long term stability of the dependencies in your code when you write it, if you want to be able to reproduce your work in the future. The example that you give uses both the dplyr and magrittr packages which may change over time. If you wanted your code to be stable you could achieve the same result without using any packages:
df <- mtcars
do.call("rbind", lapply(unique(df$gear), function(x){
data.frame(gear = x,
mpg = mean(df$mpg[df$gear == x]))
}))
It is a matter of balance between reproducibility and what you perhaps find more convenient at the time of coding and your need for the code to work next time you come to it.
I think that your specific question about solving the problem of deprecated functions in your code is not specific to R but related to any code that you write and therefore more a feature that you might expect from your text editor (Like find and replace, as you mentioned).
Upvotes: 1