Command pattern in R