Skip to content

Commit 193d2ce

Browse files
committed
refactor: formatter
1 parent 03f0e61 commit 193d2ce

46 files changed

Lines changed: 1139 additions & 351 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.Rbuildignore

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
^renv$
2-
^renv\.lock$
3-
^README\.Rmd$
4-
^README\.html$
5-
^LICENSE$
6-
.ignore
7-
.editorconfig
8-
.gitignore
9-
^.*\.Rproj$
1+
^\.agents$
2+
^\.ccache$
3+
^\.clangd$
4+
^\.claude$
5+
^\.cspell$
6+
^\.cursor$
7+
^\.editorconfig$
8+
^\.git$
9+
^\.github$
10+
^\.gitignore$
11+
^\.ignore$
12+
^\.lintr$
1013
^\.Rproj\.user$
11-
^man-roxygen$
12-
^pkgdown$
1314
^\.vscode$
14-
^\.lintr$
15-
^\.github$
16-
^\.ccache$
17-
^docs$
18-
^revdep$
15+
^.*\.Rproj$
16+
^AGENTS.md$
17+
^air.toml$
18+
^attic$
19+
^attic_local$
20+
^CITATION.cff$
21+
^CLAUDE.md$
22+
^cspell.json$
23+
^CONTRIBUTING.md$
1924
^cran-comments\.md$
2025
^CRAN-SUBMISSION$
21-
^.claude$
26+
^docs$
27+
^inst/extdata/.+\.R$
28+
^LICENSE$
29+
^local_attic$
30+
^man-roxygen$
31+
^paper$
32+
^pkgdown$
33+
^README\.Rmd$
34+
^README.html$
35+
^revdep$
36+
^tests/testthat/_object_snapshots$

.agents/mlr3.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
### Architecture
2+
3+
This package uses R6 classes organized around a dictionary registry pattern.
4+
5+
#### Class hierarchy
6+
7+
- `Learner` > `LearnerClassif` / `LearnerRegr` > concrete (e.g., `LearnerClassifRpart`)
8+
- `Task` > `TaskSupervised` > `TaskClassif` / `TaskRegr`
9+
- `Measure` > `MeasureClassif` / `MeasureRegr` / `MeasureSimilarity`
10+
- `Resampling` > `ResamplingCV`, `ResamplingHoldout`, etc.
11+
- `DataBackend` > `DataBackendDataTable`, `DataBackendCbind`, etc.
12+
- `Prediction` > `PredictionClassif` / `PredictionRegr`
13+
14+
#### File naming
15+
16+
- One R6 class per file, named exactly as the class: `LearnerClassifRpart.R` contains `LearnerClassifRpart`.
17+
- Named dataset tasks use an underscore: `TaskClassif_iris.R`.
18+
- Dictionary files: `mlr_learners.R`, `mlr_tasks.R`, etc.
19+
20+
#### Dictionary system
21+
22+
Objects are registered in dictionaries and accessed via sugar functions:
23+
24+
| Dictionary | Sugar | Example |
25+
|-----------------------|----------------------|----------------------------------|
26+
| `mlr_learners` | `lrn()` / `lrns()` | `lrn("classif.rpart", cp = 0.1)` |
27+
| `mlr_tasks` | `tsk()` / `tsks()` | `tsk("iris")` |
28+
| `mlr_measures` | `msr()` / `msrs()` | `msr("classif.ce")` |
29+
| `mlr_resamplings` | `rsmp()` / `rsmps()` | `rsmp("cv", folds = 5)` |
30+
| `mlr_task_generators` | `tgen()` / `tgens()` | `tgen("friedman1")` |
31+
32+
Every new object **must** be registered at the bottom of its file:
33+
34+
```r
35+
#' @include mlr_learners.R
36+
mlr_learners$add("classif.rpart", function() LearnerClassifRpart$new())
37+
```
38+
39+
#### Collation order
40+
41+
Derived classes must declare `#' @include ParentClass.R` in their roxygen header. This controls the `Collate:` field in DESCRIPTION so base classes load before derived classes.
42+
43+
#### Hyperparameters (paradox)
44+
45+
Parameters are defined with `paradox::ps()` and must be tagged `"train"` or `"predict"`:
46+
47+
```r
48+
ps = ps(
49+
cp = p_dbl(0, 1, default = 0.01, tags = "train"),
50+
keep_model = p_lgl(default = FALSE, tags = "train")
51+
)
52+
```
53+
54+
In `.train()` / `.predict()`, retrieve values with `self$param_set$get_values(tags = "train")`.
55+
56+
There is a distinction between `default` and `init` values:
57+
- `default` describes the behavior when a parameter is not set at all (i.e., the upstream function's default). It is informational only.
58+
- `init` (via `p_xxx(init = ...)`) sets the parameter to a value upon construction. Use this when the mlr3 default should differ from the upstream default.
59+
- A parameter tagged `"required"` causes an error if not set. A required parameter cannot have a `default` (that would be contradictory).
60+
- paradox does type-checking and range-checking automatically; `get_values()` checks that required params are present. Additional feasibility checks are rarely needed.
61+
62+
#### Core dependencies
63+
64+
`data.table`, `checkmate`, `mlr3misc`, `paradox`, `R6`, and `cli` are imported wholesale. Use their functions directly without `::`. Key mlr3misc utilities: `map()`, `map_chr()`, `invoke()`, `calculate_hash()`, `str_collapse()`, `%nin%`, `%??%`.
65+
66+
#### Error handling
67+
68+
Use structured error/warning functions from mlr3misc: `error_config()`, `error_input()`, `error_learner_train()`, `error_learner_predict()`, `warning_config()`, `warning_input()`. These support `sprintf`-style formatting.
69+
70+
#### Reflections
71+
72+
`mlr_reflections` is an environment that stores allowed types, properties, and roles. Extension packages modify it to register new task types. Check it when adding new properties or feature types.
73+
74+
### Testing
75+
76+
- Tests for `R/{name}.R` go in `tests/testthat/test_{name}.R`.
77+
- All new code should have an accompanying test.
78+
- If there are existing tests, place new tests next to similar existing tests.
79+
- Strive to keep your tests minimal with few comments.
80+
- The full test suite takes a long time. Only run tests relevant to your changes with `devtools::test(filter = '^{name}')`.
81+
- New learners must pass `run_autotest()` and `run_paramtest()`.
82+
- Use shared assertion helpers: `expect_learner()`, `expect_task()`, `expect_resampling()`, `expect_measure()`, `expect_prediction()`.
83+
- Shared test infrastructure lives in `inst/testthat/` and is sourced by extension packages too.
84+
85+
### Documentation
86+
87+
- Every user-facing function should be exported and have roxygen2 documentation.
88+
- Wrap roxygen comments at 120 characters.
89+
- Write one sentence per line.
90+
- If a sentence exceeds the limit, break at a comma, "and", "or", "but", or other appropriate point.
91+
- Internal functions should not have roxygen documentation.
92+
- Whenever you add a new (non-internal) documentation topic, also add the topic to `_pkgdown.yml`.
93+
- Always re-document the package after changing a roxygen2 comment.
94+
- Use `pkgdown::check_pkgdown()` to check that all topics are included in the reference index.
95+
- Don’t hand-edit generated artifacts: `man/`, or `NAMESPACE`.
96+
- Roxygen templates live in `man-roxygen/` (e.g., `@template learner`, `@template param_id`). Use `@templateVar` to pass values.
97+
- Bibliographic references go in `R/bibentries.R` and are cited with `` `r format_bib("key")` ``.
98+
- Man page names for dictionary objects follow `mlr_learners_classif.rpart`, `mlr_tasks_iris`, etc.
99+
- When you write examples, make sure they work.
100+
101+
### `NEWS.md`
102+
103+
- Every user-facing change should be given a bullet in `NEWS.md`. Do not add bullets for small documentation changes or internal refactorings.
104+
- Each bullet should briefly describe the change to the end user and mention the related issue in parentheses.
105+
- A bullet can consist of multiple sentences but should not contain any new lines (i.e. DO NOT line wrap).
106+
- If the change is related to a function, put the name of the function early in the bullet.
107+
- Order bullets alphabetically by function name. Put all bullets that don't mention function names at the beginning.
108+
109+
### GitHub
110+
111+
- If you use `gh` to retrieve information about an issue, always use `--comments` to read all the comments.
112+
113+
### Writing
114+
115+
- Use sentence case for headings.
116+
- Use US English.
117+
118+
### Proofreading
119+
120+
If the user asks you to proofread a file, act as an expert proofreader and editor with a deep understanding of clear, engaging, and well-structured writing.
121+
122+
Work paragraph by paragraph, always starting by making a TODO list that includes individual items for each top-level heading.
123+
124+
Fix spelling, grammar, and other minor problems without asking the user. Label any unclear, confusing, or ambiguous sentences with a FIXME comment.
125+
126+
Only report what you have changed.
127+
128+
### References
129+
130+
- [mlr3book](https://mlr3book.mlr-org.com/) — comprehensive guide to the mlr3 ecosystem.
131+
- [mlr3misc](https://github.com/mlr-org/mlr3misc) — helper functions used throughout the codebase.
132+
- [paradox](https://github.com/mlr-org/paradox) — hyperparameter/configuration space definitions.

.claude/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(gh run view:*)"
5+
]
6+
}
7+
}

.cspell/project-words.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Project-specific words — commit and share with the team.
2+
# Add words here (or via "Add to project dictionary" in VS Code / Cursor).

.editorconfig

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
# See http://editorconfig.org
22
root = true
33

4+
# settings for all files
45
[*]
5-
charset = utf-8
6-
end_of_line = lf
7-
insert_final_newline = true
8-
indent_style = space
9-
trim_trailing_whitespace = true
10-
11-
[*.{r,R,md,Rmd}]
12-
indent_size = 2
13-
14-
[*.{c,h}]
15-
indent_size = 4
16-
17-
[*.{cpp,hpp}]
18-
indent_size = 4
19-
20-
[{NEWS.md,DESCRIPTION,LICENSE}]
21-
max_line_length = 80
6+
charset = utf-8 # Ensure all files are saved in UTF-8 encoding
7+
end_of_line = lf # Use LF line endings (Unix style)
8+
indent_style = space # Use spaces for indentation
9+
indent_size = 2 # always use 2 spaces for indentation, R, C, python, etc.
10+
max_line_length = 120 # max line length
11+
trim_trailing_whitespace = true # Remove trailing whitespace

.gitignore

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
2-
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,r,macos,linux
3-
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,r,macos,linux
2+
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,r
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,macos,linux,r
44

55
### Linux ###
66
*~
@@ -150,13 +150,17 @@ $RECYCLE.BIN/
150150
# Windows shortcuts
151151
*.lnk
152152

153-
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,r,macos,linux
153+
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,r
154154

155155
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
156156

157157
# R
158158
.Rprofile
159159
README.html
160+
src/*.o
161+
src/*.so
162+
src/*.dll
163+
.clangd
160164

161165
# CRAN
162166
cran-comments.md
@@ -170,10 +174,9 @@ docs/
170174
renv/
171175
renv.lock
172176

173-
# vscode
174-
.vscode
175-
176177
# revdep
177178
revdep/
178-
check/*
179-
.claude/
179+
180+
# AI
181+
.claude/settings.local.json
182+
CLAUDE.md

.lintr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
linters: linters_with_defaults(
2-
# lintr defaults: https://github.com/jimhester/lintr#available-linters
2+
# lintr defaults: https://lintr.r-lib.org/reference/default_linters.html
33
# the following setup changes/removes certain linters
44
assignment_linter = NULL, # do not force using <- for assignments
5-
object_name_linter = object_name_linter(c("snake_case", "CamelCase")), # only allow snake case and camel case object names
5+
object_name_linter = object_name_linter(c("snake_case", "CamelCase", "SNAKE_CASE")), # only allow snake case and camel case object names
66
cyclocomp_linter = NULL, # do not check function complexity
77
commented_code_linter = NULL, # allow code in comments
8-
line_length_linter = line_length_linter(2000)
8+
line_length_linter = line_length_linter(120L), # same as .editorconfig
9+
# use indent=2 as in .editorconfig; also use block-aligned continuation with 2 space,
10+
# not “align under first argument” style.
11+
indentation_linter = indentation_linter(indent = 2L, hanging_indent_style = "never")
912
)
13+

.vscode/settings.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
3+
// ********** settings git / gitlens **********
4+
5+
// disable "blame hover", to remove visual noise
6+
"gitlens.currentLine.enabled": false,
7+
8+
// ********** settings for cspell *************
9+
// show spelling errors as hints (not in problems panel)
10+
"cSpell.diagnosticLevel": "Hint",
11+
// file type whitelist, useGitignore, and languageSettings live in cspell.json
12+
13+
// ********** settings for R *************
14+
15+
// format on save so we dont have to manually format, use AIR for formatting
16+
"[r]": {
17+
"editor.formatOnSave": true,
18+
"editor.defaultFormatter": "Posit.air-vscode",
19+
// disable hover for R, to remove visual noise
20+
"editor.hover.enabled": false
21+
},
22+
23+
// ********** settings for C / C++ **********
24+
25+
"[c]": {
26+
"editor.formatOnSave": true,
27+
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
28+
},
29+
"[cpp]": {
30+
"editor.formatOnSave": true,
31+
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
32+
}
33+
}
34+

0 commit comments

Comments
 (0)