Skip to content

Commit bf39a18

Browse files
committed
chore: use air formatting
1 parent 92cab04 commit bf39a18

17 files changed

+144
-100
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
^Meta$
77
^README\.Rmd$
88
^README\.html$
9+
^[\.]?air\.toml$
910
^\.Renviron$
1011
^\.Rproj\.user$
1112
^\.ccache$

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ repos:
44
- repo: https://github.com/lorenzwalthert/precommit
55
rev: v0.4.3.9008
66
hooks:
7-
- id: style-files
8-
args: [--style_pkg=styler.mlr, --style_fun=mlr_style]
9-
additional_dependencies:
10-
- mlr-org/styler.mlr
117
- id: roxygenize
128
additional_dependencies:
139
- R6

R/PipeOpFDACor.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#' po_cor = po("fda.cor")
2424
#' task_cor = po_cor$train(list(task))[[1L]]
2525
#' task_cor
26-
PipeOpFDACor = R6Class("PipeOpFDACor",
26+
PipeOpFDACor = R6Class(
27+
"PipeOpFDACor",
2728
inherit = PipeOpTaskPreprocSimple,
2829
public = list(
2930
#' @description Initializes a new instance of this Class.

R/PipeOpFDAExtract.R

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
#' )
5050
#' task_custom = po_custom$train(list(task))[[1L]]
5151
#' task_custom
52-
PipeOpFDAExtract = R6Class("PipeOpFDAExtract",
52+
PipeOpFDAExtract = R6Class(
53+
"PipeOpFDAExtract",
5354
inherit = PipeOpTaskPreprocSimple,
5455
public = list(
5556
#' @description Initializes a new instance of this Class.
@@ -63,41 +64,44 @@ PipeOpFDAExtract = R6Class("PipeOpFDAExtract",
6364
drop = p_lgl(tags = c("train", "predict", "required")),
6465
left = p_dbl(tags = c("train", "predict", "required")),
6566
right = p_dbl(tags = c("train", "predict", "required")),
66-
features = p_uty(tags = c("train", "predict", "required"), custom_check = crate(function(x) {
67-
if (test_character(x)) {
68-
return(check_subset(x, choices = c("mean", "median", "min", "max", "slope", "var")))
69-
}
70-
if (test_list(x)) {
71-
res = check_list(x, types = c("character", "function"), any.missing = FALSE, unique = TRUE)
72-
if (!isTRUE(res)) {
73-
return(res)
67+
features = p_uty(
68+
tags = c("train", "predict", "required"),
69+
custom_check = crate(function(x) {
70+
if (test_character(x)) {
71+
return(check_subset(x, choices = c("mean", "median", "min", "max", "slope", "var")))
7472
}
75-
nms = names2(x)
76-
res = check_names(nms[!is.na(nms)], "unique")
77-
if (!isTRUE(res)) {
78-
return(res)
79-
}
80-
for (i in seq_along(x)) {
81-
if (is.function(x[[i]])) {
82-
res = check_function(x[[i]], args = c("arg", "value"))
83-
if (!isTRUE(res)) {
84-
return(res)
85-
}
86-
res = check_names(nms[i])
87-
if (!isTRUE(res)) {
88-
return(res)
89-
}
90-
} else {
91-
res = check_choice(x[[i]], choices = c("mean", "median", "min", "max", "slope", "var"))
92-
if (!isTRUE(res)) {
93-
return(res)
73+
if (test_list(x)) {
74+
res = check_list(x, types = c("character", "function"), any.missing = FALSE, unique = TRUE)
75+
if (!isTRUE(res)) {
76+
return(res)
77+
}
78+
nms = names2(x)
79+
res = check_names(nms[!is.na(nms)], "unique")
80+
if (!isTRUE(res)) {
81+
return(res)
82+
}
83+
for (i in seq_along(x)) {
84+
if (is.function(x[[i]])) {
85+
res = check_function(x[[i]], args = c("arg", "value"))
86+
if (!isTRUE(res)) {
87+
return(res)
88+
}
89+
res = check_names(nms[i])
90+
if (!isTRUE(res)) {
91+
return(res)
92+
}
93+
} else {
94+
res = check_choice(x[[i]], choices = c("mean", "median", "min", "max", "slope", "var"))
95+
if (!isTRUE(res)) {
96+
return(res)
97+
}
9498
}
9599
}
100+
return(TRUE)
96101
}
97-
return(TRUE)
98-
}
99-
"Features must be a character or list"
100-
}))
102+
"Features must be a character or list"
103+
})
104+
)
101105
)
102106
param_set$set_values(
103107
drop = TRUE,
@@ -144,14 +148,7 @@ PipeOpFDAExtract = R6Class("PipeOpFDAExtract",
144148
if (is.function(feature)) {
145149
return(feature)
146150
}
147-
switch(feature,
148-
mean = fmean,
149-
median = fmedian,
150-
min = fmin,
151-
max = fmax,
152-
slope = fslope,
153-
var = fvar
154-
)
151+
switch(feature, mean = fmean, median = fmedian, min = fmin, max = fmax, slope = fslope, var = fvar)
155152
})
156153
fextractor = make_fextractor(features)
157154

R/PipeOpFDAFlatten.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#' task = tsk("fuel")
2222
#' pop = po("fda.flatten")
2323
#' task_flat = pop$train(list(task))
24-
PipeOpFDAFlatten = R6Class("PipeOpFDAFlatten",
24+
PipeOpFDAFlatten = R6Class(
25+
"PipeOpFDAFlatten",
2526
inherit = PipeOpTaskPreprocSimple,
2627
public = list(
2728
#' @description Initializes a new instance of this Class.

R/PipeOpFDAInterpol.R

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
#' pop = po("fda.interpol")
4646
#' task_interpol = pop$train(list(task))[[1L]]
4747
#' task_interpol$data()
48-
PipeOpFDAInterpol = R6Class("PipeOpFDAInterpol",
48+
PipeOpFDAInterpol = R6Class(
49+
"PipeOpFDAInterpol",
4950
inherit = PipeOpTaskPreprocSimple,
5051
public = list(
5152
#' @description Initializes a new instance of this Class.
@@ -56,17 +57,22 @@ PipeOpFDAInterpol = R6Class("PipeOpFDAInterpol",
5657
#' otherwise be set during construction. Default `list()`.
5758
initialize = function(id = "fda.interpol", param_vals = list()) {
5859
param_set = ps(
59-
grid = p_uty(tags = c("train", "predict", "required"), custom_check = crate(function(x) {
60-
if (test_string(x)) {
61-
return(check_choice(x, choices = c("union", "intersect", "minmax")))
62-
}
63-
if (test_numeric(x, any.missing = FALSE, min.len = 1L)) {
64-
return(TRUE)
65-
}
66-
"Must be either a string or numeric vector"
67-
})),
60+
grid = p_uty(
61+
tags = c("train", "predict", "required"),
62+
custom_check = crate(function(x) {
63+
if (test_string(x)) {
64+
return(check_choice(x, choices = c("union", "intersect", "minmax")))
65+
}
66+
if (test_numeric(x, any.missing = FALSE, min.len = 1L)) {
67+
return(TRUE)
68+
}
69+
"Must be either a string or numeric vector"
70+
})
71+
),
6872
method = p_fct(
69-
c("linear", "spline", "fill_extend", "locf", "nocb"), default = "linear", tags = c("train", "predict")
73+
c("linear", "spline", "fill_extend", "locf", "nocb"),
74+
default = "linear",
75+
tags = c("train", "predict")
7076
),
7177
left = p_dbl(tags = c("train", "predict")),
7278
right = p_dbl(tags = c("train", "predict"))

R/PipeOpFDAScaleRange.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#' po_scale = po("fda.scalerange", lower = -1, upper = 1)
2222
#' task_scale = po_scale$train(list(task))[[1L]]
2323
#' task_scale$data()
24-
PipeOpFDAScaleRange = R6Class("PipeOpFDAScaleRange",
24+
PipeOpFDAScaleRange = R6Class(
25+
"PipeOpFDAScaleRange",
2526
inherit = PipeOpTaskPreproc,
2627
public = list(
2728
#' @description Initializes a new instance of this Class.

R/PipeOpFDASmooth.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#' task_smooth = po_smooth$train(list(task))[[1L]]
3232
#' task_smooth
3333
#' task_smooth$data(cols = c("NIR", "UVVIS"))
34-
PipeOpFDASmooth = R6Class("PipeOpFDASmooth",
34+
PipeOpFDASmooth = R6Class(
35+
"PipeOpFDASmooth",
3536
inherit = PipeOpTaskPreprocSimple,
3637
public = list(
3738
#' @description Initializes a new instance of this Class.
@@ -42,9 +43,14 @@ PipeOpFDASmooth = R6Class("PipeOpFDASmooth",
4243
#' otherwise be set during construction. Default `list()`.
4344
initialize = function(id = "fda.smooth", param_vals = list()) {
4445
param_set = ps(
45-
method = p_fct(default = "lowess", c("lowess", "rollmean", "rollmedian", "savgol"), tags = c("train", "predict")), # nolint
46+
method = p_fct(
47+
default = "lowess",
48+
c("lowess", "rollmean", "rollmedian", "savgol"),
49+
tags = c("train", "predict")
50+
),
4651
args = p_uty(
47-
tags = c("train", "predict", "required"), custom_check = crate(function(x) check_list(x, names = "unique"))
52+
tags = c("train", "predict", "required"),
53+
custom_check = crate(function(x) check_list(x, names = "unique"))
4854
),
4955
verbose = p_lgl(tags = c("train", "predict", "required"))
5056
)
@@ -72,7 +78,8 @@ PipeOpFDASmooth = R6Class("PipeOpFDASmooth",
7278
return(dt)
7379
}
7480
for (j in seq_along(dt)) {
75-
set(dt,
81+
set(
82+
dt,
7683
j = j,
7784
value = suppressMessages(invoke(tf::tf_smooth, x = dt[[j]], method = pars$method, .args = pars$args))
7885
)

R/PipeOpFDATsfeatures.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#' po_tsfeats = po("fda.tsfeats")
3939
#' task_tsfeats = po_tsfeats$train(list(task))[[1L]]
4040
#' task_tsfeats$data()
41-
PipeOpFDATsfeatures = R6Class("PipeOpFDATsfeatures",
41+
PipeOpFDATsfeatures = R6Class(
42+
"PipeOpFDATsfeatures",
4243
inherit = PipeOpTaskPreprocSimple,
4344
public = list(
4445
#' @description Initializes a new instance of this Class.

R/PipeOpFPCA.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#' po_fpca = po("fda.fpca", n_components = 3L)
2929
#' task_fpca = po_fpca$train(list(task))[[1L]]
3030
#' task_fpca$data()
31-
PipeOpFPCA = R6Class("PipeOpFPCA",
31+
PipeOpFPCA = R6Class(
32+
"PipeOpFPCA",
3233
inherit = PipeOpTaskPreproc,
3334
public = list(
3435
#' @description Initializes a new instance of this Class.

R/bibentries.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#' @importFrom utils bibentry
22
# nolint start
33
bibentries = c(
4-
ferraty2003curves = bibentry("article",
4+
ferraty2003curves = bibentry(
5+
"article",
56
title = "Curves discrimination: a nonparametric functional approach",
67
author = "Ferraty, Fr\xc3\xa9dric and Vieu, Philippe",
78
journal = "Computational Statistics & Data Analysis",
@@ -11,7 +12,8 @@ bibentries = c(
1112
year = "2003",
1213
publisher = "Elsevier"
1314
),
14-
brockhaus2015functional = bibentry("article",
15+
brockhaus2015functional = bibentry(
16+
"article",
1517
title = "The functional linear array model",
1618
author = "Brockhaus, Sarah and Scheipl, Fabian and Hothorn, Torsten and Greven, Sonja",
1719
journal = "Statistical Modelling",
@@ -21,7 +23,8 @@ bibentries = c(
2123
year = "2015",
2224
publisher = "SAGE Publications Sage India: New Delhi, India"
2325
),
24-
goldsmith2011penalized = bibentry("article",
26+
goldsmith2011penalized = bibentry(
27+
"article",
2528
title = "Penalized functional regression",
2629
author = "Goldsmith, Jeff and Bobb, Jennifer and Crainiceanu, Ciprian M and Caffo, Brian and Reich, Daniel",
2730
journal = "Journal of Computational and Graphical Statistics",

R/zzz.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ register_mlr3pipelines = function() {
6464
register_namespace_callback(pkgname, "mlr3pipelines", register_mlr3pipelines)
6565
}
6666

67-
.onUnload = function(libPaths) { # nolint
67+
.onUnload = function(libPaths) {
6868
walk(names(mlr3fda_tasks), function(nm) mlr_tasks$remove(nm))
6969
walk(names(mlr3fda_pipeops), function(nm) mlr_pipeops$remove(nm))
7070
mlr_reflections$task_feature_types =

air.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[format]
2+
line-width = 120

inst/bench/bench.R

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ library(mlr3pipelines)
55
set.seed(1234)
66
setDTthreads(threads = 1)
77

8-
generate_data = function(n_patients = 100,
9-
n_weeks = 10,
10-
type = c("reg", "irreg")) {
8+
generate_data = function(n_patients = 100, n_weeks = 10, type = c("reg", "irreg")) {
119
type = match.arg(type)
1210
if (type == "reg") {
1311
week = 1:n_weeks
@@ -52,27 +50,29 @@ analyse_dplyr = function(patients, window_start, window_end, choice) {
5250

5351
analyse_dt = function(patients, window_start, window_end, choice) {
5452
if (choice == "one") {
55-
patients[between(week, window_start, window_end), .(
56-
mean = mean(measurement_value)
57-
), keyby = .(patient_id, measurement_type)]
53+
patients[
54+
between(week, window_start, window_end),
55+
.(
56+
mean = mean(measurement_value)
57+
),
58+
keyby = .(patient_id, measurement_type)
59+
]
5860
} else {
59-
patients[between(week, window_start, window_end), .(
60-
mean = mean(measurement_value),
61-
var = var(measurement_value),
62-
slope = coef(lm(measurement_value ~ week))[[2]]
63-
), keyby = .(patient_id, measurement_type)]
61+
patients[
62+
between(week, window_start, window_end),
63+
.(
64+
mean = mean(measurement_value),
65+
var = var(measurement_value),
66+
slope = coef(lm(measurement_value ~ week))[[2]]
67+
),
68+
keyby = .(patient_id, measurement_type)
69+
]
6470
}
6571
}
6672

6773
build_graph = function(left, right, choice) {
6874
features = switch(choice, one = "mean", three = c("mean", "var", "slope"))
69-
po("ffs",
70-
features = features,
71-
id = "features",
72-
drop = FALSE,
73-
left = left,
74-
right = right
75-
)
75+
po("ffs", features = features, id = "features", drop = FALSE, left = left, right = right)
7676
}
7777

7878
analyse_fda = function(graph, task) {
@@ -88,7 +88,9 @@ results_one = bench::press(
8888
window_end = floor(n_weeks * 0.8)
8989

9090
patients = generate_data(
91-
n_patients = n_patients, n_weeks = n_weeks, type = type
91+
n_patients = n_patients,
92+
n_weeks = n_weeks,
93+
type = type
9294
)
9395
patients_long = patients |>
9496
tidyr::pivot_longer(
@@ -129,7 +131,9 @@ results_three = bench::press(
129131
window_end = floor(n_weeks * 0.8)
130132

131133
patients = generate_data(
132-
n_patients = n_patients, n_weeks = n_weeks, type = type
134+
n_patients = n_patients,
135+
n_weeks = n_weeks,
136+
type = type
133137
)
134138
patients_long = patients |>
135139
tidyr::pivot_longer(

tests/testthat/test_PipeOpFDAExtract.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ test_that("PipeOpFDAExtract works", {
5050
pop = po("fda.extract", features = c("mean", "median", "min"), drop = TRUE, left = 100, right = 200)
5151
task_pop = train_pipeop(pop, list(task))[[1L]]
5252
expected = data.table(
53-
y = 1:2, f_mean = rep(NA_real_, 2L), f_median = rep(NA_real_, 2L), f_min = rep(NA_real_, 2L)
53+
y = 1:2,
54+
f_mean = rep(NA_real_, 2L),
55+
f_median = rep(NA_real_, 2L),
56+
f_min = rep(NA_real_, 2L)
5457
)
5558
expect_identical(task_pop$data(), expected)
5659

@@ -184,9 +187,7 @@ test_that("ffind works", {
184187
expect_identical(ffind(1:10, 5, 15), c(5L, 10L))
185188

186189
expect_identical(
187-
ffind(c(-3876, -3798, -3453, -3363, -2974, -2953, -2871, -1917, -1335, -1304, -725, 10),
188-
left = -200, right = 0
189-
),
190+
ffind(c(-3876, -3798, -3453, -3363, -2974, -2953, -2871, -1917, -1335, -1304, -725, 10), left = -200, right = 0),
190191
rep(NA_integer_, 2L)
191192
)
192193
})

0 commit comments

Comments
 (0)