@@ -109,11 +109,31 @@ pkg_doc_codedoc_df__ <- function(
109109pkg_doc_obj <- function (
110110 regex ,
111111 rdname = NULL ,
112- text_file_paths = NULL
112+ text_file_paths = NULL ,
113+ grepl_arg_list = NULL
113114) {
114115 # @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-06-18", "0.10.0")
115116 # New function `codedoc::pkg_doc_obj`.
116117 # @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-06-18", "0.10.0")
118+
119+ # @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-03", "0.10.2")
120+ # `codedoc::pkg_doc_obj` gains new arg `grepl_arg_list`.
121+ # @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-03", "0.10.2")
122+ # ' @param grepl_arg_list `[NULL, list]` (default `NULL`)
123+ # '
124+ # ' Additional arguments to pass to `grepl` when detecting which comment
125+ # ' blocks to include based on `key`.
126+ # ' Arguments `pattern`, `x`, and `perl = TRUE` cannot be changed.
127+ # '
128+ # ' - `NULL`: No additional arguments.
129+ # ' - `list`: Pass these.
130+ dbc :: assert_is_one_of(
131+ grepl_arg_list ,
132+ funs = list (dbc :: report_is_NULL ,
133+ dbc :: report_is_list )
134+ )
135+ grepl_arg_list <- as.list(grepl_arg_list )
136+
117137 # @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-02", "0.10.1")
118138 # Expand `codedoc::pkg_doc_obj` allowed `regex` patterns.
119139 # Now `regex` can be any string that `grepl(perl = TRUE)` can handle.
@@ -132,8 +152,11 @@ pkg_doc_obj <- function(
132152 # ' use `roxygen` blocks normally unless there is a special reason to do
133153 # ' otherwise.
134154 dbc :: assert_is_character_nonNA_atom(regex )
155+ grepl_arg_list [[" pattern" ]] <- regex
156+ grepl_arg_list [[" x" ]] <- " test"
157+ grepl_arg_list [[" perl" ]] <- TRUE
135158 regex_test <- suppressWarnings(tryCatch(
136- grepl( regex , " a " , perl = TRUE ), error = function (e ) e
159+ do.call( grepl , grepl_arg_list ), error = function (e ) e
137160 ))
138161 if (inherits(regex_test , " error" )) {
139162 stop(" Invalid `regex`: " , regex_test [[" message" ]])
@@ -203,9 +226,10 @@ pkg_doc_obj <- function(
203226 " descr" = paste0(" ^" , regex , " $" ),
204227 " return" = paste0(" ^return[(]" , regex , " [)]$" )
205228 )
229+ grepl_arg_list [[" x" ]] <- df [[" key" ]]
206230 lines_by_section <- lapply(names(regexes ), function (nm ) {
207- regex <- regexes [nm ]
208- lines <- df [[" comment_block" ]][grepl( regex , df [[ " key " ]], perl = TRUE )]
231+ grepl_arg_list [[ " pattern " ]] <- regexes [nm ]
232+ lines <- df [[" comment_block" ]][do.call( grepl , grepl_arg_list )]
209233 if (length(lines ) > 0 ) {
210234 head <- switch (
211235 nm ,
@@ -282,7 +306,8 @@ pkg_doc_obj <- function(
282306pkg_doc_fun <- function (
283307 regex ,
284308 rdname = NULL ,
285- text_file_paths = NULL
309+ text_file_paths = NULL ,
310+ grepl_arg_list = NULL
286311) {
287312 # @codedoc_comment_block codedoc::pkg_doc_obj
288313 # Document a function in an R package. Wrapper for
@@ -297,10 +322,14 @@ pkg_doc_fun <- function(
297322 # @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-06-18", "0.10.0")
298323 # `codedoc::pkg_doc_fun` now a wrapper for `codedoc::pkg_doc_obj`.
299324 # @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-06-18", "0.10.0")
325+ # @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-07-03", "0.10.2")
326+ # `codedoc::pkg_doc_fun` gains new arg `grepl_arg_list`.
327+ # @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-07-03", "0.10.2")
300328 return (codedoc :: pkg_doc_obj(
301329 regex = regex ,
302330 rdname = rdname ,
303- text_file_paths = text_file_paths
331+ text_file_paths = text_file_paths ,
332+ grepl_arg_list = grepl_arg_list
304333 ))
305334}
306335
0 commit comments