Skip to content

Commit cd33739

Browse files
authored
refactor: formatter (#105)
1 parent 6c2cd72 commit cd33739

36 files changed

Lines changed: 1324 additions & 391 deletions

.Rbuildignore

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1-
^renv$
2-
^renv\.lock$
3-
^.*\.Rproj$
4-
^\.Rproj\.user$
5-
^\.pre-commit-config\.yaml$
6-
^\.lintr$
7-
^\.github$
1+
^\.agents$
82
^\.ccache$
9-
^codemeta\.json$
10-
pkgdown
11-
^_pkgdown\.yml$
3+
^\.clangd$
4+
^\.claude$
5+
^\.cspell$
6+
^\.cursor$
7+
^\.editorconfig$
8+
^\.git$
9+
^\.github$
10+
^\.gitignore$
11+
^\.ignore$
12+
^\.lintr$
13+
^\.Rproj\.user$
14+
^\.vscode$
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$
24+
^cran-comments\.md$
25+
^CRAN-SUBMISSION$
1226
^docs$
13-
^pkgdown$
14-
attic/
15-
target*
16-
^.*\.xml$
27+
^inst/extdata/.+\.R$
28+
^LICENSE$
29+
^local_attic$
1730
^man-roxygen$
18-
cran-comments\.md
19-
^CRAN-RELEASE$
20-
^CRAN-SUBMISSION$
21-
.editorconfig
31+
^paper$
32+
^pkgdown$
2233
^README\.Rmd$
23-
^README\.html$
24-
.vscode
25-
^cran-comments\.md$
34+
^README.html$
35+
^revdep$
36+
^tests/testthat/_object_snapshots$

.Rprofile

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

.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.

.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: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
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,macos,linux,r
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,macos,linux,r
24

3-
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,r
4-
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,r
5+
### Linux ###
6+
*~
7+
8+
# temporary files which can be created if a process still has a handle open of a deleted file
9+
.fuse_hidden*
10+
11+
# KDE directory preferences
12+
.directory
13+
14+
# Linux trash folder which might appear on any partition or disk
15+
.Trash-*
16+
17+
# .nfs files are created when an open file is removed but is still being accessed
18+
.nfs*
519

620
### macOS ###
721
# General
@@ -32,13 +46,18 @@ Network Trash Folder
3246
Temporary Items
3347
.apdisk
3448

49+
### macOS Patch ###
50+
# iCloud generated files
51+
*.icloud
52+
3553
### R ###
3654
# History files
3755
.Rhistory
3856
.Rapp.history
3957

4058
# Session Data files
4159
.RData
60+
.RDataTmp
4261

4362
# User-specific files
4463
.Ruserdata
@@ -79,6 +98,9 @@ docs/
7998
# translation temp files
8099
po/*~
81100

101+
# RStudio Connect folder
102+
rsconnect/
103+
82104
### R.Bookdown Stack ###
83105
# R package: bookdown caching files
84106
/*_files/
@@ -89,24 +111,72 @@ po/*~
89111
!.vscode/tasks.json
90112
!.vscode/launch.json
91113
!.vscode/extensions.json
92-
*.code-workspace
114+
!.vscode/*.code-snippets
93115

94116
# Local History for Visual Studio Code
95117
.history/
96118

119+
# Built Visual Studio Code Extensions
120+
*.vsix
121+
97122
### VisualStudioCode Patch ###
98123
# Ignore all local history of files
99124
.history
100125
.ionide
101126

102-
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,r
127+
### Windows ###
128+
# Windows thumbnail cache files
129+
Thumbs.db
130+
Thumbs.db:encryptable
131+
ehthumbs.db
132+
ehthumbs_vista.db
133+
134+
# Dump file
135+
*.stackdump
136+
137+
# Folder config file
138+
[Dd]esktop.ini
139+
140+
# Recycle Bin used on file shares
141+
$RECYCLE.BIN/
142+
143+
# Windows Installer files
144+
*.cab
145+
*.msi
146+
*.msix
147+
*.msm
148+
*.msp
149+
150+
# Windows shortcuts
151+
*.lnk
152+
153+
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,macos,linux,r
103154

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

106-
*.xml
107-
inst/doc
108-
cran-comments\.md
157+
# R
158+
.Rprofile
159+
README.html
160+
src/*.o
161+
src/*.so
162+
src/*.dll
163+
.clangd
164+
165+
# CRAN
166+
cran-comments.md
109167
CRAN-RELEASE
110-
.vscode
111-
README\.html
112168
CRAN-SUBMISSION
169+
170+
# pkgdown
171+
docs/
172+
173+
# renv
174+
renv/
175+
renv.lock
176+
177+
# revdep
178+
revdep/
179+
180+
# AI
181+
.claude/settings.local.json
182+
CLAUDE.md

.lintr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
linters: with_defaults(
2-
# lintr defaults: https://github.com/jimhester/lintr#available-linters
1+
linters: linters_with_defaults(
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(200)
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+

0 commit comments

Comments
 (0)