@maxheld83 maybe you'll be interested in this, I updated my package and it's full of new function operators and an API to easily build them or use them. If you are I'll be happy to read your thoughts.
EDIT:
@maxheld83 these packages are now ready to be used, there's more than 50 tags (function operator factories). I made adverb factories from all the purrr and base adverbs, all the with_* functions from withr, progress::progress_bar and much more. See README intro below :
This package consists of a collection of tags built using the functions and
principle designed and described in the package tag. See the read me at :
https://github.com/moodymudskipper/tag.
It allows things like the following :
library(tags)
df_name <- "iris"
# use quasi quotation with any function
using_bang$head(!!rlang::sym(df_name),1)
# use purrr adverbs with tag syntax
using_possibly$log("a", .otherwise = NA_real_)
# use withr functions with tag syntax
setting_options(list(scipen = 100))$print(exp(100))
Installation and setup :
# devtools::install_github("moodymudskipper/tag")
# devtools::install_github("moodymudskipper/tags")
library(tags)
suppressPackageStartupMessages(library(tidyverse,warn.conflicts = FALSE))
The package contains over 50 tags that can be divided into the
following categories.
- tag counterparts to
base and purrr adverbs :
-
vectorizing (wraps base::Vectorize)
-
negating (wraps base::Negate)
-
using_safely (borrows code from purrr::safely)
-
using_quietly (borrows code from purrr::quietly)
-
using_possibly (borrows code from purrr::possibly)
- tag counterparts to
withr functions :
- all 31
withr::with_* functions have tags::setting_* counterparts
- tag expanding tidyverse features :
-
using_bang to make any function compatible with quasi-quotation
-
using_lambda to use formula notation in any functional
-
grouping_by to use dplyr::group_by on a single operation
-
using_rowwise to use dplyr::rowwise on a single operation
-
selecting_dots, renaming_dots, mutating_dots, transmuting_dots,
reversing_dots to edit the dots passed to a call before it's executed,
using dplyr semantics.
- tags focused on side effects
-
logging to print call and execution time (wraps Sys.time())
-
suppressing_warnings to selectively suppress warnings based on a regular
expression.
-
viewing (wraps utils::View)
-
debugging (wraps base::debugonce)
-
progressing to add a progress bar to any functional (wraps progress::progress_bar)
-
beeping to play a sound once the call is over (wraps beepr::beep)
-
popping_up to trigger a message box once the call is over (wraps tcltk::tk_messageBox)
- other tags
-
composing as an alternative to piping/functional sequences (wraps magrittr's functional sequences)
-
using as the tag counterpart to with, with extra features
-
mapping to loop over argument values (wraps foreach::foreach)
-
self_referencing to avoid variable repetition with functions such as
base::transform / dplyr::mutate, dplyr::summarize
-
tracing as a tag counterpart to base::trace
-
enclosing to enclose the input function in another function.
-
preserving_attr to make sure some attributes are preserved
-
checking_args to operate checks on arguments before calling the function