In R, is it possible to assign an operator to a variable or some other construct that allows the variable to be used as an operator? In my case, I want some code to use either the %do% or %dopar% operator from the foreach package (depending on whether the user wants parallel computation or not). The block of code to execute remains the same, its just the operator that’s variable.
Share
This is called operator overloading, and here is a simple example: