Skip to content

Commit 823f182

Browse files
committed
feat: add pkg_doc_obj
1 parent 8a36096 commit 823f182

File tree

5 files changed

+98
-38
lines changed

5 files changed

+98
-38
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export(example_text_file_path)
2222
export(example_text_file_paths)
2323
export(extract_keyed_comment_blocks)
2424
export(pkg_doc_fun)
25+
export(pkg_doc_obj)
2526
export(pkg_doc_package_description)
2627
export(render_codedoc)
2728
export(render_codedoc_)

NEWS.md

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

3+
## News for version 0.10.0
4+
5+
### codedoc::pkg_doc_fun
6+
7+
`codedoc::pkg_doc_fun` now a wrapper for `codedoc::pkg_doc_obj`.
8+
9+
### codedoc::pkg_doc_obj
10+
11+
New function `codedoc::pkg_doc_obj`.
12+
313
## News for version 0.9.0
414

515
### codedoc::pkg_doc_fun

R/pkg_doc.R

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,15 @@ pkg_doc_codedoc_df__ <- function(
105105
return(.__PKG_DOC_ENV__.[["codedoc_df"]])
106106
}
107107

108-
#' @eval codedoc:::pkg_doc_fun("codedoc::pkg_doc_fun", "pkg_doc")
109-
pkg_doc_fun <- function(
108+
#' @eval codedoc:::pkg_doc_fun("codedoc::pkg_doc_obj", "pkg_doc")
109+
pkg_doc_obj <- function(
110110
regex,
111111
rdname = NULL,
112112
text_file_paths = NULL
113113
) {
114-
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-03-10", "0.6.0")
115-
# New fun `codedoc::pkg_doc_fun`.
116-
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-03-10", "0.6.0")
117-
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-04-24", "0.9.0")
118-
# Fix for `codedoc::pkg_doc_fun` not being exported.
119-
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-04-24", "0.9.0")
114+
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-06-18", "0.10.0")
115+
# New function `codedoc::pkg_doc_obj`.
116+
# @codedoc_comment_block news("codedoc::pkg_doc_obj", "2025-06-18", "0.10.0")
120117
dbc::assert_match_regex(
121118
regex,
122119
grepl.arg.list = list(pattern = "^[a-zA-Z0-9._-]+::[a-zA-Z0-9._-]+$")
@@ -156,15 +153,15 @@ pkg_doc_fun <- function(
156153
}
157154

158155

159-
# @codedoc_comment_block codedoc::pkg_doc_fun
160-
# Document a function in an R package.
156+
# @codedoc_comment_block codedoc::pkg_doc_obj
157+
# Document an object in an R package.
161158
#
162159
# Performs the following steps.
163160
# - Calls `[codedoc::extract_keyed_comment_blocks]`.
164-
# @codedoc_comment_block codedoc::pkg_doc_fun
161+
# @codedoc_comment_block codedoc::pkg_doc_obj
165162
#' @param text_file_paths `[NULL, character]` (default `NULL`)
166163
#'
167-
#' - `codedoc::pkg_doc_fun`:
164+
#' - `codedoc::pkg_doc_obj`:
168165
#' Passed to `codedoc::codedoc_lines` and
169166
#' `codedoc::codedoc_roxygen_news_by_version` calls.
170167
#' @param regex `[character]` (no default)
@@ -183,17 +180,17 @@ pkg_doc_fun <- function(
183180
dir_path = getwd(),
184181
text_file_paths = text_file_paths
185182
)
186-
# @codedoc_comment_block codedoc::pkg_doc_fun
183+
# @codedoc_comment_block codedoc::pkg_doc_obj
187184
# - Collect comment block lines whose keys match one of:
188185
# + `paste0("^", regex, "::")` for arguments --- but you should use roxygen
189186
# block directly unless you have a specific reason.
190187
# + `paste0("^", regex, "$")` for the description of the function.
191188
# These go into either `Details` or section `Functions`, depending on
192189
# `rdname`.
193-
# + `paste0("^return[(]", regex, "[)]$")` for docs describing the what the
190+
# + `paste0("^return[(]", regex, "[)]$")` for docs describing what the
194191
# function returns. These appear under the section `Value` in the help
195192
# page.
196-
# @codedoc_comment_block codedoc::pkg_doc_fun
193+
# @codedoc_comment_block codedoc::pkg_doc_obj
197194
regexes <- c(
198195
"param" = paste0("^", regex, "::"),
199196
"descr" = paste0("^", regex, "$"),
@@ -215,31 +212,27 @@ pkg_doc_fun <- function(
215212
})
216213
names(lines_by_section) <- names(regexes)
217214

218-
# @codedoc_comment_block codedoc::pkg_doc_fun
215+
# @codedoc_comment_block codedoc::pkg_doc_obj
219216
# - Call `[codedoc::codedoc_roxygen_news_by_version]` to extract news for
220217
# the function, if any.
221-
# @codedoc_comment_block codedoc::pkg_doc_fun
218+
# @codedoc_comment_block codedoc::pkg_doc_obj
222219
lines_by_section[["news"]] <- codedoc::codedoc_roxygen_news_by_version(
223220
regex,
224221
text_file_paths
225222
)
226223

227-
# @codedoc_comment_block codedoc::pkg_doc_fun
228-
# @codedoc_insert_comment_block explain(codedoc::pkg_doc_fun, maker)
229-
# @codedoc_comment_block codedoc::pkg_doc_fun
230-
231-
# @codedoc_comment_block explain(codedoc::pkg_doc_fun, maker)
224+
# @codedoc_comment_block codedoc::pkg_doc_obj
232225
# - If `regex` looks something like `xx::xx_make_column_xxxx`, matching
233226
# regular expression
234227
# `^[a-zA-Z0-9._-]+::[a-zA-Z0-9._-]+_make_column_[a-zA-Z0-9._-]+$`,
235228
# its argument names which do not contain the words `dataset` or `setting`
236229
# are assumed to be column names and are documented simply with
237230
# ${gsub("`", "", deparse1(doc_fun_col_arg__("some.column")))}.
238231
# This means you don't have to document such column arguments separately.
239-
# @codedoc_comment_block explain(codedoc::pkg_doc_fun, maker)
232+
# @codedoc_comment_block codedoc::pkg_doc_obj
240233
re_maker <- "^[a-zA-Z0-9._-]+::[a-zA-Z0-9._-]+_make_column_[a-zA-Z0-9._-]+$"
241234
if (grepl(re_maker, regex)) {
242-
fun <- tryCatch(
235+
obj <- tryCatch(
243236
# replace :: -> ::: just in case it is not yet exported.
244237
eval(parse(text = gsub(":+", ":::", regex))),
245238
error = function(e) {
@@ -252,30 +245,58 @@ pkg_doc_fun <- function(
252245
)
253246
}
254247
)
255-
arg_nms <- names(formals(fun))
256-
col_arg_nms <- arg_nms[!grepl("(dataset)|(setting)", arg_nms)]
257-
lines_by_section[["param"]] <- c(
258-
lines_by_section[["param"]],
259-
unlist(lapply(col_arg_nms, doc_fun_col_arg__))
260-
)
248+
if (is.function(obj)) {
249+
arg_nms <- names(formals(obj))
250+
col_arg_nms <- arg_nms[!grepl("(dataset)|(setting)", arg_nms)]
251+
lines_by_section[["param"]] <- c(
252+
lines_by_section[["param"]],
253+
unlist(lapply(col_arg_nms, doc_fun_col_arg__))
254+
)
255+
}
261256
}
262257

263-
# @codedoc_comment_block codedoc::pkg_doc_fun
258+
# @codedoc_comment_block codedoc::pkg_doc_obj
264259
# - Finally, collect all docs into one long string vector and add `@export`
265260
# to the beginning of the vector.
266-
# @codedoc_comment_block codedoc::pkg_doc_fun
261+
# @codedoc_comment_block codedoc::pkg_doc_obj
267262
lines <- c(
268263
"@export",
269264
rdname_line,
270265
"",
271266
unlist(lines_by_section, use.names = FALSE)
272267
)
273-
# @codedoc_comment_block return(codedoc::pkg_doc_fun)
268+
# @codedoc_comment_block return(codedoc::pkg_doc_obj)
274269
# Returns a `character` vector of lines for further processing by `roxygen2`.
275-
# @codedoc_comment_block return(codedoc::pkg_doc_fun)
270+
# @codedoc_comment_block return(codedoc::pkg_doc_obj)
276271
return(lines)
277272
}
278273

274+
#' @eval codedoc:::pkg_doc_fun("codedoc::pkg_doc_fun", "pkg_doc")
275+
pkg_doc_fun <- function(
276+
regex,
277+
rdname = NULL,
278+
text_file_paths = NULL
279+
) {
280+
# @codedoc_comment_block codedoc::pkg_doc_obj
281+
# Document a function in an R package. Wrapper for
282+
# `codedoc::pkg_doc_fun` .
283+
# @codedoc_comment_block codedoc::pkg_doc_obj
284+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-03-10", "0.6.0")
285+
# New fun `codedoc::pkg_doc_fun`.
286+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-03-10", "0.6.0")
287+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-04-24", "0.9.0")
288+
# Fix for `codedoc::pkg_doc_fun` not being exported.
289+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-04-24", "0.9.0")
290+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-06-18", "0.10.0")
291+
# `codedoc::pkg_doc_fun` now a wrapper for `codedoc::pkg_doc_obj`.
292+
# @codedoc_comment_block news("codedoc::pkg_doc_fun", "2025-06-18", "0.10.0")
293+
return(codedoc::pkg_doc_obj(
294+
regex = regex,
295+
rdname = rdname,
296+
text_file_paths = text_file_paths
297+
))
298+
}
299+
279300
#' @eval codedoc:::pkg_doc_fun("codedoc::pkg_doc_package_description", "pkg_doc")
280301
pkg_doc_package_description <- function(
281302
text_file_paths = NULL,

man/codedoc-package.Rd

Lines changed: 13 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: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)