Skip to content

Commit a143469

Browse files
authored
Merge pull request #87 from pythonhealthdatascience/dev
Dev
2 parents e9b01ab + 5d15e40 commit a143469

File tree

15 files changed

+1208
-79
lines changed

15 files changed

+1208
-79
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,3 @@ figure_*.html
231231

232232
_site/
233233
**/*.quarto_ipynb
234-
235-
_csv_data_dictionary.pdf
236-
_json_data_dictionary.pdf

.lintr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
linters: all_linters(packages = "lintr")
1+
linters: all_linters(packages = "lintr", undesirable_function_linter = NULL)
22
encoding: "UTF-8"
33
exclusions: list("renv")

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Imports:
1616
R6,
1717
rstudioapi,
1818
simEd,
19+
simmer,
1920
styler,
2021
testthat,
2122
webexercises

environment.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ dependencies:
1212
- pytest=8.4.1
1313
- python=3.11
1414
- ruff=0.12.7
15+
- simpy=4.1.1
1516
- pip:
1617
- ansi2html==1.9.2
1718
- distfit==1.8.8
1819
- jupytext==1.17.2
1920
- lintquarto==0.5.0
20-
- sim-tools==0.7.0
21+
- sim-tools==0.10.0

pages/inputs/input_data.qmd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ The way you might set these up depends on whether you are allowed to share the r
247247
## 🧪 Test yourself
248248

249249
```{r, echo = FALSE}
250-
library(webexercises) # nolint: undesirable_function_linter
250+
library(webexercises) # nolint: library_call_linter
251251
```
252252

253253
:::{.callout-note}
@@ -257,7 +257,10 @@ library(webexercises) # nolint: undesirable_function_linter
257257
```{r, results="asis", echo = FALSE}
258258
cat(longmcq(c(
259259
"Do not share or describe anything.",
260-
answer = "Describe the dataset, and if possible also share a data dictionary and a synthetic dataset."
260+
answer = paste0(
261+
"Describe the dataset, and if possible also share a data dictionary and a",
262+
" synthetic dataset."
263+
)
261264
)))
262265
```
263266

@@ -283,7 +286,10 @@ cat(longmcq(c(
283286
```{r, results="asis", echo = FALSE}
284287
cat(longmcq(c(
285288
"Duplicate all simulation code across both repositories.",
286-
answer = "Develop the simulation code as a package so it can be shared across repositories without code duplication."
289+
answer = paste(
290+
"Develop the simulation code as a package so it can be shared across ",
291+
"repositories without code duplication."
292+
)
287293
)))
288294
```
289295

pages/inputs/parameters_script.qmd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This page helps you meet reproducibility criteria from:
3434
:::{.r-content}
3535
```{r}
3636
# Load required packages
37-
library(R6) # nolint: undesirable_function_linter
37+
library(R6)
3838
```
3939
:::
4040

@@ -1238,7 +1238,7 @@ Not applicable as the stroke example stores [parameters in a file](parameters_fi
12381238
## 🧪 Test yourself
12391239

12401240
```{r, echo = FALSE}
1241-
library(webexercises) # nolint: undesirable_function_linter
1241+
library(webexercises) # nolint: library_call_linter
12421242
```
12431243

12441244
:::{.callout-note}
@@ -1261,7 +1261,10 @@ cat(longmcq(c(
12611261

12621262
```{r, results="asis", echo = FALSE}
12631263
cat(longmcq(c(
1264-
answer = "It ensures that each scenario only uses the parameters intended for it, and avoids accidental reuse between runs.",
1264+
answer = paste0(
1265+
"It ensures that each scenario only uses the parameters intended for it, ",
1266+
"and avoids accidental reuse between runs."
1267+
),
12651268
"It always makes your code shorter.",
12661269
"It allows you to skip documenting your parameters."
12671270
)))

pages/inputs/parameters_validation.qmd

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ The prevention of new fields is thanks to the default `lock_objects = TRUE` sett
829829
#' @field transfer_prob Numeric. Transfer probability (0-1).
830830
831831
ParamClass <- R6Class( # nolint: object_name_linter
832-
lock_objects = FALSE,
832+
lock_objects = FALSE,
833833
public = list(
834834
transfer_prob = NULL,
835835
@@ -851,7 +851,7 @@ params <- ParamClass$new()
851851
try({
852852
params$transfer_probs <- 0.4
853853
})
854-
params
854+
params
855855
```
856856

857857
#### Setting parameters within a list
@@ -867,15 +867,15 @@ You may choose to store parameters in a list instead, to make it easier to acces
867867
868868
ParamClass <- R6Class( # nolint: object_name_linter
869869
public = list(
870-
parameters = NULL,
870+
parameters = NULL,
871871
872872
#' @description
873873
#' Initialises the R6 object.
874874
875875
initialize = function(transfer_prob = 0.3) {
876-
self$parameters <- list(
876+
self$parameters <- list(
877877
transfer_prob = transfer_prob
878-
)
878+
)
879879
}
880880
)
881881
)
@@ -889,7 +889,7 @@ params <- ParamClass$new()
889889
try({
890890
params$parameters$transfer_probs <- 0.4
891891
})
892-
params$parameters
892+
params$parameters
893893
```
894894

895895
<br>
@@ -912,20 +912,20 @@ ParamClass <- R6Class( # nolint: object_name_linter
912912
self$transfer_prob <- transfer_prob
913913
},
914914
915-
#' @description
916-
#' Returns parameters as a named list.
917-
918-
get_params = function() {
919-
# Get all non-function fields
920-
all_names <- ls(self)
921-
is_not_function <- vapply(
922-
all_names,
923-
function(x) !is.function(self[[x]]),
924-
FUN.VALUE = logical(1L)
925-
)
926-
param_names <- all_names[is_not_function]
927-
mget(param_names, envir = self)
928-
}
915+
#' @description
916+
#' Returns parameters as a named list.
917+
918+
get_params = function() {
919+
# Get all non-function fields
920+
all_names <- ls(self)
921+
is_not_function <- vapply(
922+
all_names,
923+
function(x) !is.function(self[[x]]),
924+
FUN.VALUE = logical(1L)
925+
)
926+
param_names <- all_names[is_not_function]
927+
mget(param_names, envir = self)
928+
}
929929
)
930930
)
931931
```
@@ -939,8 +939,8 @@ try({
939939
params$transfer_probs <- 0.4
940940
})
941941
942-
# Get all parameters
943-
params$get_params()
942+
# Get all parameters
943+
params$get_params()
944944
```
945945

946946
::::
@@ -1055,7 +1055,7 @@ model <- function(param) {
10551055
10561056
# Simulation code...
10571057
1058-
print("The simulation has run!")
1058+
cat("The simulation has run!")
10591059
}
10601060
10611061
@@ -1180,26 +1180,26 @@ ParamClass <- R6Class( # nolint: object_name_linter
11801180
self$transfer_prob <- transfer_prob
11811181
},
11821182
1183-
#' @description
1184-
#' Check that transfer_prob is between 0 and 1.
1185-
#' @return No return value; throws an error if invalid.
1186-
1187-
validate_param = function() {
1188-
if (self$transfer_prob < 0L || self$transfer_prob > 1L) {
1189-
stop(
1190-
"transfer_prob must be between 0 and 1, but is: ",
1191-
self$transfer_prob, call. = FALSE
1192-
)
1193-
}
1194-
}
1183+
#' @description
1184+
#' Check that transfer_prob is between 0 and 1.
1185+
#' @return No return value; throws an error if invalid.
1186+
1187+
validate_param = function() {
1188+
if (self$transfer_prob < 0L || self$transfer_prob > 1L) {
1189+
stop(
1190+
"transfer_prob must be between 0 and 1, but is: ",
1191+
self$transfer_prob, call. = FALSE
1192+
)
1193+
}
1194+
}
11951195
)
11961196
)
11971197
```
11981198

11991199
```{r}
12001200
# Create instance with invalid transfer_prob and run method
12011201
param <- ParamClass$new(transfer_prob = 1.4)
1202-
try(param$validate_param())
1202+
try(param$validate_param())
12031203
```
12041204

12051205
:::
@@ -1287,4 +1287,4 @@ If you haven't already, now's the time to try out **parameter validation** in pr
12871287

12881288
* Repeat this task, but with an **invalid value** for a parameter (e.g. outside the expected range).
12891289

1290-
<br><br>
1290+
<br><br>

pages/intro/foss.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Both have extensive **documentation**, **active user communities**, and **proven
7979
## 🧪 Test yourself
8080

8181
```{r, echo = FALSE}
82-
library(webexercises) # nolint: undesirable_function_linter
82+
library(webexercises)
8383
```
8484

8585
:::{.callout-note}

pages/intro/rap.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ This book does both! As detailed on the [guidelines](guidelines.qmd) page:
8686
## 🧪 Test yourself
8787

8888
```{r, echo = FALSE}
89-
library(webexercises) # nolint: undesirable_function_linter
89+
library(webexercises)
9090
```
9191

9292
:::{.callout-note}

0 commit comments

Comments
 (0)