Skip to content

Commit ce5f295

Browse files
authored
Merge pull request #27 from SticsRPacks/setup-flint-action
Create style.yaml
2 parents b784b05 + 2e6411d commit ce5f295

35 files changed

+629
-404
lines changed

.github/workflows/style.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
pull_request:
5+
paths:
6+
[
7+
"**.[rR]",
8+
"**.[qrR]md",
9+
"**.[rR]markdown",
10+
"**.[rR]nw",
11+
"**.[rR]profile",
12+
]
13+
workflow_dispatch:
14+
15+
name: style
16+
17+
permissions: read-all
18+
19+
jobs:
20+
style:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
env:
25+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
26+
steps:
27+
- name: Checkout repo
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Setup R
33+
uses: r-lib/actions/setup-r@v2
34+
with:
35+
use-public-rspm: true
36+
37+
- name: Install dependencies
38+
uses: r-lib/actions/setup-r-dependencies@v2
39+
with:
40+
extra-packages: any::styler, any::roxygen2
41+
needs: styler
42+
43+
- name: Enable styler cache
44+
run: styler::cache_activate()
45+
shell: Rscript {0}
46+
47+
- name: Determine cache location
48+
id: styler-location
49+
run: |
50+
cat(
51+
"location=",
52+
styler::cache_info(format = "tabular")$location,
53+
"\n",
54+
file = Sys.getenv("GITHUB_OUTPUT"),
55+
append = TRUE,
56+
sep = ""
57+
)
58+
shell: Rscript {0}
59+
60+
- name: Cache styler
61+
uses: actions/cache@v4
62+
with:
63+
path: ${{ steps.styler-location.outputs.location }}
64+
key: ${{ runner.os }}-styler-${{ github.sha }}
65+
restore-keys: |
66+
${{ runner.os }}-styler-
67+
${{ runner.os }}-
68+
69+
- name: Style
70+
run: styler::style_pkg()
71+
shell: Rscript {0}
72+
73+
- name: Commit and push changes
74+
run: |
75+
if FILES_TO_COMMIT=($(git diff-index --name-only ${{ github.sha }} \
76+
| egrep --ignore-case '\.(R|[qR]md|Rmarkdown|Rnw|Rprofile)$'))
77+
then
78+
git config --local user.name "$GITHUB_ACTOR"
79+
git config --local user.email "[email protected]"
80+
git commit ${FILES_TO_COMMIT[*]} -m "Style code (GHA)"
81+
git pull --ff-only
82+
git push origin
83+
else
84+
echo "No changes to commit."
85+
fi

R/FwdRegAgMIP.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ select_param_FwdRegAgMIP <- function(oblig_param_list, add_param_list, crt_list,
4747
return(res)
4848
} else if (crt_list[length(crt_list)] ==
4949
add_param_list[length(add_param_list)]) {
50-
5150
# we tested all parameters
5251
if (crt_info_crit < min(prev_info_crit)) {
5352
res$selected <- TRUE
@@ -56,7 +55,6 @@ select_param_FwdRegAgMIP <- function(oblig_param_list, add_param_list, crt_list,
5655
}
5756
return(res)
5857
} else if (length(crt_list) == length(oblig_param_list)) {
59-
6058
# we only tested so far the obligatory parameters
6159
res$selected <- TRUE
6260
res$next_candidates <- c(oblig_param_list, add_param_list[1])
@@ -69,7 +67,6 @@ select_param_FwdRegAgMIP <- function(oblig_param_list, add_param_list, crt_list,
6967
add_param_list[which(add_param_list == crt_list[length(crt_list)]) + 1]
7068
)
7169
} else {
72-
7370
# Replace the last candidate parameter by the next candidate
7471
res$selected <- FALSE
7572
res$next_candidates <- c(
@@ -118,7 +115,8 @@ post_treat_FwdRegAgMIP <- function(optim_results, crit_options, crt_list,
118115

119116
## Store the results per step
120117
v_init <- as.vector(
121-
t(optim_results$init_values[optim_results$ind_min_crit, ]))
118+
t(optim_results$init_values[optim_results$ind_min_crit, ])
119+
)
122120
names(v_init) <- names(optim_results$init_values)
123121
info_new_step <- setNames(
124122
tibble::tibble(
@@ -138,7 +136,7 @@ post_treat_FwdRegAgMIP <- function(optim_results, crit_options, crt_list,
138136
info_crit_func()$name, "Selected step"
139137
)
140138
)
141-
param_selection_steps <- dplyr::bind_rows(param_selection_steps, info_new_step)
139+
param_selection_steps <- dplyr::bind_rows(param_selection_steps, info_new_step)
142140
ind_min_infocrit <- which.min(param_selection_steps[[info_crit_func()$name]])
143141
param_selection_steps[, "Selected step"] <- ""
144142
param_selection_steps[ind_min_infocrit, "Selected step"] <- "X"

R/bayesian_functions.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ plot_bayesian <- function(optim_options, param_info, optim_results) {
5252
nb_chains <- length(out$chain)
5353
nb_iterations <- nrow(optim_results$post_sample) / nb_chains
5454

55-
tryCatch({
55+
tryCatch(
56+
{
5657
grDevices::pdf(
5758
file = file.path(path_results, "iterAndDensityPlots.pdf"),
5859
width = 9, height = 9
@@ -81,7 +82,8 @@ plot_bayesian <- function(optim_options, param_info, optim_results) {
8182
}
8283
)
8384

84-
tryCatch({
85+
tryCatch(
86+
{
8587
grDevices::pdf(
8688
file = file.path(path_results, "marginalPlots.pdf"),
8789
width = 9, height = 9
@@ -110,7 +112,8 @@ plot_bayesian <- function(optim_options, param_info, optim_results) {
110112
)
111113

112114
if (nb_params >= 2) {
113-
tryCatch({
115+
tryCatch(
116+
{
114117
grDevices::pdf(
115118
file = file.path(path_results, "correlationPlots.pdf"),
116119
width = 9, height = 9
@@ -145,7 +148,8 @@ plot_bayesian <- function(optim_options, param_info, optim_results) {
145148
# an error
146149
if (is.null(optim_options$thin)) optim_options$thin <- 1
147150
if (nb_iterations >= (optim_options$thin + 50)) {
148-
tryCatch({
151+
tryCatch(
152+
{
149153
grDevices::pdf(
150154
file = file.path(path_results, "gelmanDiagPlots.pdf"),
151155
width = 9, height = 9

R/compute_eq_const.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,48 @@
1111
#' @keywords internal
1212
#'
1313
compute_eq_const <- function(forced_param_values, param_values) {
14-
1514
comp_forced_values <- NULL
1615
is_vector <- is.vector(param_values)
1716
if (!is.null(forced_param_values)) {
18-
1917
param_values <- tibble::tibble(!!!param_values)
2018
param_values$situation <- NULL
21-
nrows <- max(1,seq_len(nrow(param_values)))
22-
comp_forced_values <- matrix(ncol = length(forced_param_values),
23-
nrow = nrows)
19+
nrows <- max(1, seq_len(nrow(param_values)))
20+
comp_forced_values <- matrix(
21+
ncol = length(forced_param_values),
22+
nrow = nrows
23+
)
2424
colnames(comp_forced_values) <- names(forced_param_values)
2525

2626
# Backticks are added here and in the following to handle parameters names
2727
# including special characters
2828
expr_ls <-
29-
lapply(names(forced_param_values), function(x) paste0("`",x,"`","<-",
30-
forced_param_values[[x]]))
29+
lapply(names(forced_param_values), function(x) {
30+
paste0(
31+
"`", x, "`", "<-",
32+
forced_param_values[[x]]
33+
)
34+
})
3135
names(expr_ls) <- names(forced_param_values)
3236

3337
for (irow in 1:nrows) {
34-
3538
for (par in names(param_values)) {
36-
eval(parse(text = paste0("`",par,"`","<-",param_values[[irow, par]])))
39+
eval(parse(text = paste0("`", par, "`", "<-", param_values[[irow, par]])))
3740
}
3841
for (par in names(forced_param_values)) {
3942
eval(parse(text = expr_ls[[par]]))
40-
eval(parse(text = paste0("comp_forced_values[irow,\"",par,"\"] <- ",
41-
"`",par,"`")))
43+
eval(parse(text = paste0(
44+
"comp_forced_values[irow,\"", par, "\"] <- ",
45+
"`", par, "`"
46+
)))
4247
}
43-
4448
}
4549

4650
if (is_vector) {
47-
comp_forced_values <- comp_forced_values[1,]
51+
comp_forced_values <- comp_forced_values[1, ]
4852
} else {
4953
comp_forced_values <- tibble::as_tibble(comp_forced_values)
5054
}
51-
5255
}
5356

5457
return(comp_forced_values)
55-
5658
}
57-

R/estim_param.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ estim_param <- function(obs_list, crit_function = crit_log_cwss, model_function,
198198
CroptimizR::BIC, CroptimizR::AICc,
199199
CroptimizR::AIC
200200
),
201-
weight=NULL,
201+
weight = NULL,
202202
var_names = lifecycle::deprecated()) {
203-
204203
# Managing parameter names changes between versions:
205204
if (rlang::has_name(optim_options, "path_results")) {
206205
lifecycle::deprecate_warn("0.5.0", "estim_param(optim_options = 'is deprecated, use `out_dir` instead of `path_results`')")
@@ -299,12 +298,14 @@ estim_param <- function(obs_list, crit_function = crit_log_cwss, model_function,
299298
"The following parameters are defined both in forced_param_values and param_info
300299
arguments of estim_param function while they should not (a parameter cannot
301300
be both forced and estimated except if it is part of the `candidate` parameters):",
302-
paste(tmp,collapse = ","),
301+
paste(tmp, collapse = ","),
303302
"\n They will be removed from forced_param_values."
304303
)
305304
forced_param_values <-
306-
forced_param_values[setdiff(names(forced_param_values),
307-
setdiff(param_names, candidate_param))]
305+
forced_param_values[setdiff(
306+
names(forced_param_values),
307+
setdiff(param_names, candidate_param)
308+
)]
308309
}
309310
}
310311

@@ -360,8 +361,8 @@ estim_param <- function(obs_list, crit_function = crit_log_cwss, model_function,
360361
crt_candidates <- oblig_param_list
361362
if (length(crt_candidates) == 0) crt_candidates <- candidate_param[[1]] # in case there are only candidates ...
362363
count <- 1
363-
param_selection_steps<-NULL
364-
tmp <- optim_switch(optim_method=optim_method,optim_options=optim_options)
364+
param_selection_steps <- NULL
365+
tmp <- optim_switch(optim_method = optim_method, optim_options = optim_options)
365366

366367
# Parameter selection loop
367368
while (!is.null(crt_candidates)) {
@@ -422,7 +423,7 @@ estim_param <- function(obs_list, crit_function = crit_log_cwss, model_function,
422423
forced_param_values = forced_param_values_tmp,
423424
info_level = info_level,
424425
info_crit_list = info_crit_list,
425-
weight=weight
426+
weight = weight
426427
)
427428

428429
## Run the estimation
@@ -432,14 +433,13 @@ estim_param <- function(obs_list, crit_function = crit_log_cwss, model_function,
432433
)
433434

434435
## In case no results, there was an error during the estimation process => stop
435-
if (length(res_tmp)==0) {
436+
if (length(res_tmp) == 0) {
436437
stop("There was an error during the parameter estimation process.
437438
Please check warnings and messages displayed above and/or by running warnings().")
438439
}
439440

440441
## The following is done only if parameter selection is activated
441442
if (!is.null(candidate_param)) {
442-
443443
### Update results in param_selection_steps
444444
param_selection_steps <- post_treat_FwdRegAgMIP(
445445
res_tmp, crit_options,
@@ -465,8 +465,10 @@ estim_param <- function(obs_list, crit_function = crit_log_cwss, model_function,
465465

466466
# Print and store results of parameter estimation steps if parameter selection was activated
467467
if (!is.null(candidate_param)) {
468-
summary_FwdRegAgMIP(param_selection_steps, info_crit_list, path_results_ORI,
469-
res)
468+
summary_FwdRegAgMIP(
469+
param_selection_steps, info_crit_list, path_results_ORI,
470+
res
471+
)
470472
save_results_FwdRegAgMIP(param_selection_steps, path_results_ORI)
471473
res$param_selection_steps <- param_selection_steps
472474
}

R/filter_obs.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
filter_obs <- function(obs_list, var = NULL, situation = NULL, dates = NULL,
4242
include = FALSE, var_names = lifecycle::deprecated(),
4343
sit_names = lifecycle::deprecated()) {
44-
4544
# Managing parameter names changes between versions:
4645
if (lifecycle::is_present(sit_names)) {
4746
lifecycle::deprecate_warn("0.5.0", "filter_obs(sit_names)", "filter_obs(situation)")

0 commit comments

Comments
 (0)