The variables storing the regular expressions can be created and loaded just like the functions in your package. For example, let's say you made a file named is_foobar.R and stored it in the package's R/ subdirectory:
# is_foobar.R
#' @export
my_regexes <- list(
foo = "\\bfoo\\b",
bar = "(bar){3}"
)
#' @export
is_foobar <- function(x) {
grepl(my_regexes[["foo"]], x) & grepl(my_regexes[["bar"]], x)
}
Now both my_regexes and is_foobar are available if users load your package.
library(mypackage)
is_foobar(c("foo", "bar", "foo barbarbar"))
# [1] FALSE FALSE TRUE
my_regexes
# $`foo`
# [1] "\\bfoo\\b"
#
# $bar
# [1] "(bar){3}"
If a user just wants the regular expressions but nothing else, they can use :: notation:
test::my_regexes
# $`foo`
# [1] "\\bfoo\\b"
#
# $bar
# [1] "(bar){3}"