## 1. Basic usage
# Will print('a') and return 'a'
no_op('a', print)
# Will do nothing and return 'a' because .check_fun is false
no_op('a', print, .check_fun = FALSE)
# Will print('a') and return 'a'
no_op('a', print(.), .check_fun = FALSE)
## 2. Toy example
library(graphics)
par(mfrow = c(2,2))
x <- rnorm(100)
# hist and plot share the same input `rnorm(100)`
y <- x |>
# .expr is a function, all ... are passed as other arguments
no_op( hist, nclass = 10 ) |>
no_op( plot, x = seq(0,1,length.out = 100) ) |>
# Repeat the previous two plots, but with different syntax
no_op({ hist(., nclass = 10) }) |>
no_op({ plot(x = seq(0,1,length.out = 100), y = .) }) |>
# The return statement is ignored
no_op({ return(x + 1)})
# x is returned at the end
identical(x, y) # TRUE
Run the code above in your browser using DataLab