Skip to content

Commit d96356d

Browse files
restructure script
1 parent a1d66a1 commit d96356d

File tree

4 files changed

+83
-59
lines changed

4 files changed

+83
-59
lines changed

.ci/check-options.R

Lines changed: 0 additions & 38 deletions
This file was deleted.

.ci/linters/rd/options_doc_check.R

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Ensure that data.table options in code match documentation
2+
check_options_documentation = function(rd_file) {
3+
if (!grepl("data.table-options", rd_file)) return(invisible())
4+
5+
# Find options in R code
6+
get_options_from_code = function() {
7+
found = character(0)
8+
9+
walk_ast = function(expr) {
10+
result = character(0)
11+
if (is.call(expr) && length(expr) >= 2 && identical(expr[[1]], quote(getOption)) && is.character(expr[[2]]) && startsWith(expr[[2]], "datatable.")) {
12+
result = expr[[2]]
13+
}
14+
if (is.recursive(expr)) {
15+
result = c(result, unlist(lapply(expr, walk_ast)))
16+
}
17+
result
18+
}
19+
r_files = list.files("R", pattern = "\\.R$", full.names = TRUE)
20+
for (file in r_files) {
21+
tryCatch({
22+
found = c(found, unlist(lapply(parse(file = file), walk_ast)))
23+
}, error = function(e) {})
24+
}
25+
sort(unique(found))
26+
}
27+
28+
# Find options in documentation
29+
get_options_from_doc = function(rd_file) {
30+
if (!file.exists(rd_file)) return(character(0))
31+
32+
tryCatch({
33+
found = character(0)
34+
walk_rd = function(rd_element) {
35+
result = character(0)
36+
if (is.list(rd_element)) {
37+
if (!is.null(attr(rd_element, "Rd_tag")) && attr(rd_element, "Rd_tag") == "\\code" && length(rd_element) >= 1) {
38+
content = rd_element[[1]]
39+
if (is.character(content) && startsWith(content, "datatable.")) {
40+
result = content
41+
}
42+
}
43+
result = c(result, unlist(lapply(rd_element, walk_rd)))
44+
}
45+
result
46+
}
47+
found = walk_rd(tools::parse_Rd(rd_file))
48+
sort(unique(found))
49+
}, error = function(e) character(0))
50+
}
51+
52+
code_opts = get_options_from_code()
53+
doc_opts = get_options_from_doc(rd_file)
54+
code_opts = setdiff(code_opts, "datatable.alloc")
55+
56+
miss_in_doc = setdiff(code_opts, doc_opts)
57+
miss_in_code = setdiff(doc_opts, code_opts)
58+
59+
if (length(miss_in_doc) > 0 || length(miss_in_code) > 0) {
60+
if (length(miss_in_doc) > 0) {
61+
cat("Options in code but missing from docs:", paste(miss_in_doc, collapse = ", "), "\n")
62+
}
63+
if (length(miss_in_code) > 0) {
64+
cat("Options in docs but not in code:", paste(miss_in_code, collapse = ", "), "\n")
65+
}
66+
stop("Please sync man/data.table-options.Rd with code options")
67+
}
68+
}

.github/workflows/code-quality.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ jobs:
6262
- name: Lint
6363
run: for (f in list.files('.ci/linters/md', full.names=TRUE)) source(f)
6464
shell: Rscript {0}
65+
lint-rd:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v4
69+
- uses: r-lib/actions/setup-r@v2
70+
- name: Lint Rd files
71+
run: Rscript .ci/lint.R .ci/linters/rd man '[.]Rd$'
72+

man/data.table-options.Rd

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77
\description{
88
The data.table package uses a number of global options to control its
99
behavior. These are regular R options that can be set with options()
10-
and retrieved with getOption().
10+
and retrieved with getOption(). For example:
11+
\preformatted{
12+
# Get the current value of an option
13+
getOption("datatable.print.topn")
1114

15+
# Set a new value for an option
16+
options(datatable.print.topn = 10)
17+
}
1218
This page provides a comprehensive, up-to-date list of all user-configurable
1319
options.
1420
}
1521

16-
\usage{
17-
\preformatted{
18-
# Get the current value of an option
19-
getOption("datatable.print.topn")
20-
21-
# Set a new value for an option
22-
options(datatable.print.topn = 10)
23-
}
24-
}
25-
2622
\section{Printing Options}{
2723
\describe{
2824
\item{\code{datatable.print.topn}}{An integer. When a data.table is printed,
@@ -132,16 +128,6 @@ options(datatable.print.topn = 10)
132128
\item{\code{datatable.verbose}}{A logical. If \code{TRUE}, `data.table` will
133129
print detailed diagnostic information as it processes a query.
134130
Default: \code{FALSE}.}
135-
\item{\code{datatable.pedantic}}{A logical. If \code{TRUE}, `data.table`
136-
enters a "pedantic" mode, issuing helpful warnings for potentially
137-
unintentional user behavior.
138-
Default: \code{FALSE}.}
139-
\item{\code{datatable.dfdispatchwarn}}{A logical. If \code{TRUE}, warns
140-
when a generic function from another package is applied to a `data.table`.
141-
Default: \code{TRUE}.}
142-
\item{\code{datatable.warnredundantby}}{A logical. If \code{TRUE}, `data.table`
143-
will warn when grouping by columns that are already the key of the table.
144-
Default: \code{TRUE}.}
145131
\item{\code{datatable.enlist}}{Experimental feature. If set to a function
146132
(e.g., `list`), the `j` expression can return a `list`, which will then
147133
be "enlisted" into columns in the result.

0 commit comments

Comments
 (0)