Skip to content

Instantly share code, notes, and snippets.

@francisbarton
Created January 12, 2025 22:13
Show Gist options
  • Select an option

  • Save francisbarton/30ae5dbe75cd6d8db71ad4c3919bb11e to your computer and use it in GitHub Desktop.

Select an option

Save francisbarton/30ae5dbe75cd6d8db71ad4c3919bb11e to your computer and use it in GitHub Desktop.
gregg
#' Conveniently wrap a regular expr in glue::glue_data() and pass to `grepl()`
#'
#' Use {glue} expressions in grepl (and put the arguments the right way round)
#' https://glue.tidyverse.org/articles/wrappers.html
#'
#' @param x A character vector to check
#' @param rx A string that after processing by glue_data() will be used as a
#' regex pattern in `grepl()`
#' @param ... Arguments passed onto `grepl()`
#' @param g The parent frame of gregg, which must be passed through to `glue()`
#' @keywords internal
# old_gregg <- \(x, rx, ...) grepl(glue(rx), x, ...)
# gregg <- \(x, rx, ..., e = parent.frame()) grepl(glue(rx, .envir = e), x, ...)
gregg <- \(x, rx, ..., g = parent.frame()) grepl(glue_data(g, rx), x, ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment