This is reproducible minimal dataset and function because it is not the point. my real function is very complicated but that's not the point in here.
id <- 1:30
x<-rnorm(30,1,10)
y<-rnorm(30,1,10)
data<-data.frame(id,x,y)
try<-function(data,
x,
y){
require(tidyverse)
data<-data %>%
mutate(new=x+y)
return(data)
}
the feedback I got was:
1)Generally, it's a good practice to avoid using require() or library() within a function.
however, I am using tidyverse grammar (%>% etc ) in my user-defined function so if I do not use require(), I am very confused what option that I have.