Skip to content

Commit ee9edd2

Browse files
committed
feat: add detect_allowed_keys_grepl_arg_list
1 parent 8448e4b commit ee9edd2

File tree

6 files changed

+124
-17
lines changed

6 files changed

+124
-17
lines changed

NEWS.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<!-- generated by R package codedoc; do not modify! -->
22

3+
## News for version 0.10.3
4+
5+
### codedoc::extract_keyed_comment_blocks
6+
7+
New argument `detect_allowed_keys_grepl_arg_list`.
8+
9+
### codedoc::pkg_doc_obj
10+
11+
`codedoc::pkg_doc_obj` argument `grepl_arg_list` handling improved:
12+
- By default `perl = TRUE` but user can override this.
13+
- If user supplies `fixed = TRUE`, we always set `perl = FALSE`.
14+
15+
316
## News for version 0.10.2
417

518
### codedoc::pkg_doc_fun
@@ -16,7 +29,7 @@
1629
### codedoc::pkg_doc_obj
1730

1831
Expand `codedoc::pkg_doc_obj` allowed `regex` patterns.
19-
Now `regex` can be any string that `grepl(perl = TRUE)` can handle.
32+
Now `regex` can be any string that `grepl` can handle.
2033

2134

2235
## News for version 0.10.0

R/collect_raw.R

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ extract_keyed_comment_blocks <- function(
140140
sort_by = NULL,
141141
readLines_arg_list = list(warn = FALSE),
142142
string_interpolation_eval_env = parent.frame(1L),
143+
detect_allowed_keys_grepl_arg_list = NULL,
143144
assertion_type = "input"
144145
) {
145146
# @codedoc_comment_block news("codedoc::extract_keyed_comment_blocks", "2022-02-17", "0.2.15")
@@ -192,7 +193,8 @@ extract_keyed_comment_blocks <- function(
192193
insert = TRUE,
193194
interpolate = TRUE,
194195
assertion_type = assertion_type,
195-
call = match.call()
196+
call = match.call(),
197+
detect_allowed_keys_grepl_arg_list = detect_allowed_keys_grepl_arg_list
196198
)
197199
}
198200

@@ -324,7 +326,8 @@ extract_keyed_comment_blocks__ <- function(
324326
insert = TRUE,
325327
interpolate = TRUE,
326328
assertion_type = "input",
327-
call = NULL
329+
call = NULL,
330+
detect_allowed_keys_grepl_arg_list = NULL
328331
) {
329332
main_call <- dbc::handle_arg_call(call)
330333
extract_keyed_comment_blocks_assertions__(
@@ -500,6 +503,30 @@ extract_keyed_comment_blocks__ <- function(
500503
# @codedoc_comment_block codedoc:::extract_keyed_comment_blocks__
501504

502505
if (is.character(detect_allowed_keys)) {
506+
# @codedoc_comment_block codedoc:::extract_keyed_comment_blocks__
507+
# @param detect_allowed_keys_grepl_arg_list `[NULL, list]`
508+
# (optional, default `NULL`)
509+
#
510+
# Additional arguments passed to `grepl` when `detect_allowed_keys`
511+
# is a regex. By default we set
512+
# `detect_allowed_keys_grepl_arg_list$fixed <- FALSE`
513+
# but this can be overridden by the user. If `fixed = TRUE`, we override
514+
# `detect_allowed_keys_grepl_arg_list$perl <- FALSE`.
515+
#
516+
# - `NULL`: No additional arguments.
517+
# - `list`: These arguments, e.g. `list(fixed = TRUE)`.
518+
# @codedoc_comment_block codedoc:::extract_keyed_comment_blocks__
519+
# @codedoc_comment_block news("codedoc::extract_keyed_comment_blocks", "2025-07-03", "0.10.3")
520+
# New argument `detect_allowed_keys_grepl_arg_list`.
521+
# @codedoc_comment_block news("codedoc::extract_keyed_comment_blocks", "2025-07-03", "0.10.3")
522+
detect_allowed_keys_grepl_arg_list <- as.list(
523+
detect_allowed_keys_grepl_arg_list
524+
)
525+
if (!"fixed" %in% names(detect_allowed_keys_grepl_arg_list)) {
526+
detect_allowed_keys_grepl_arg_list[["fixed"]] <- FALSE
527+
} else if (detect_allowed_keys_grepl_arg_list[["fixed"]] == TRUE) {
528+
detect_allowed_keys_grepl_arg_list[["perl"]] <- FALSE
529+
}
503530
# @codedoc_comment_block codedoc:::extract_keyed_comment_blocks__
504531
# @param detect_allowed_keys `[character, function]`
505532
# (optional, default `""`)
@@ -515,9 +542,10 @@ extract_keyed_comment_blocks__ <- function(
515542
# returned in output. therefore, comment blocks that need to be inserted into
516543
# the ones you want to retain in output are kept for the insertion phase.
517544
# @codedoc_comment_block codedoc:::extract_keyed_comment_blocks__
518-
detect_allowed_keys_regex <- detect_allowed_keys
545+
detect_allowed_keys_grepl_arg_list[["pattern"]] <- detect_allowed_keys
519546
detect_allowed_keys <- function(x) {
520-
grepl(detect_allowed_keys_regex, x)
547+
detect_allowed_keys_grepl_arg_list[["x"]] <- x
548+
do.call(grepl, detect_allowed_keys_grepl_arg_list)
521549
}
522550
}
523551

R/pkg_doc.R

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pkg_doc_obj <- function(
123123
#'
124124
#' Additional arguments to pass to `grepl` when detecting which comment
125125
#' blocks to include based on `key`.
126-
#' Arguments `pattern`, `x`, and `perl = TRUE` cannot be changed.
126+
#' Arguments `pattern` and `x` cannot be changed.
127127
#'
128128
#' - `NULL`: No additional arguments.
129129
#' - `list`: Pass these.
@@ -132,15 +132,38 @@ pkg_doc_obj <- function(
132132
funs = list(dbc::report_is_NULL,
133133
dbc::report_is_list)
134134
)
135+
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-03", "0.10.3")
136+
# `codedoc::pkg_doc_obj` argument `grepl_arg_list` handling improved:
137+
# - By default `perl = TRUE` but user can override this.
138+
# - If user supplies `fixed = TRUE`, we always set `perl = FALSE`.
139+
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-03", "0.10.3")
140+
# @codedoc_comment_block codedoc::pkg_doc_obj
141+
# Document an object in an R package.
142+
#
143+
# Performs the following steps.
144+
# - Set `grepl_arg_list$perl <- TRUE` and `grepl_arg_list$fixed <- FALSE`
145+
# by default but the user can override these.
146+
# - If user supplies `grepl_arg_list$fixed = TRUE` via we always set
147+
# `grepl_arg_list$perl <- FALSE`.
148+
# @codedoc_comment_block codedoc::pkg_doc_obj
135149
grepl_arg_list <- as.list(grepl_arg_list)
150+
if (!"perl" %in% names(grepl_arg_list)) {
151+
grepl_arg_list[["perl"]] <- TRUE
152+
}
153+
if (!"fixed" %in% names(grepl_arg_list)) {
154+
grepl_arg_list[["fixed"]] <- FALSE
155+
}
156+
if (grepl_arg_list[["fixed"]] == TRUE) {
157+
grepl_arg_list[["perl"]] <- FALSE
158+
}
136159

137160
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-02", "0.10.1")
138161
# Expand `codedoc::pkg_doc_obj` allowed `regex` patterns.
139-
# Now `regex` can be any string that `grepl(perl = TRUE)` can handle.
162+
# Now `regex` can be any string that `grepl` can handle.
140163
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-07-02", "0.10.1")
141164
#' @param regex `[character]` (no default)
142165
#'
143-
#' Any regular expression accepted by `grepl(perl = TRUE)`.
166+
#' Any regular expression accepted by `grepl`.
144167
#' E.g. `"mypkg::myfun"`, where you write
145168
#' `codedoc` comment blocks with `mypkg::myfun` as/in the keys.
146169
#' This is used to detect which `codedoc` comment blocks to use in
@@ -152,9 +175,9 @@ pkg_doc_obj <- function(
152175
#' use `roxygen` blocks normally unless there is a special reason to do
153176
#' otherwise.
154177
dbc::assert_is_character_nonNA_atom(regex)
178+
155179
grepl_arg_list[["pattern"]] <- regex
156180
grepl_arg_list[["x"]] <- "test"
157-
grepl_arg_list[["perl"]] <- TRUE
158181
regex_test <- suppressWarnings(tryCatch(
159182
do.call(grepl, grepl_arg_list), error = function(e) e
160183
))
@@ -196,9 +219,6 @@ pkg_doc_obj <- function(
196219
}
197220

198221
# @codedoc_comment_block codedoc::pkg_doc_obj
199-
# Document an object in an R package.
200-
#
201-
# Performs the following steps.
202222
# - Calls `[codedoc::extract_keyed_comment_blocks]`.
203223
# @codedoc_comment_block codedoc::pkg_doc_obj
204224
#' @param text_file_paths `[NULL, character]` (default `NULL`)
@@ -249,7 +269,8 @@ pkg_doc_obj <- function(
249269
# @codedoc_comment_block codedoc::pkg_doc_obj
250270
lines_by_section[["news"]] <- codedoc::codedoc_roxygen_news_by_version(
251271
regex,
252-
text_file_paths
272+
text_file_paths,
273+
extract_arg_list = list(detect_allowed_keys_grepl_arg_list = grepl_arg_list)
253274
)
254275

255276
# @codedoc_comment_block codedoc::pkg_doc_obj

man/codedoc-package.Rd

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/extract_keyed_comment_blocks.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pkg_doc.Rd

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)