A simple reproducible example to pass arguments to data.table in a self-defined function in R

I have been googling this answer for a few hours. A lot of people have asked similar questions, but I did not find either a simple enough question or a straightforward answer. Here is my approach: Assume that I want to do a simple group by in data.table: library(data.table) mtcars = data.table(mtcars) mtcars[,sum(mpg), gear] # […]