Skip to content

Commit

Permalink
strict testing (#202)
Browse files Browse the repository at this point in the history
- added options for strict testing
- add `pre-commit.yaml`
- solve all lintr issues
- solve all spelling issues

---------

Signed-off-by: André Veríssimo <[email protected]>
Signed-off-by: Pawel Rucki <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Co-authored-by: Joe Zhu <[email protected]>
  • Loading branch information
3 people authored Mar 11, 2024
1 parent 2ac5374 commit d17033f
Show file tree
Hide file tree
Showing 84 changed files with 1,064 additions and 381 deletions.
13 changes: 13 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120L),
cyclocomp_linter = NULL,
object_usage_linter = NULL,
object_name_linter = object_name_linter(
styles = c("snake_case", "symbols"),
regexes = c(
ANL = "^ANL_?[0-9A-Z_]*$",
ADaM = "^r?AD[A-Z]{2,5}_?[0-9]*$",
ADaM_variables = "^AVAL$|^USUBJID$|^PARAMCD$|^PARAM$"
)
)
)
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.0
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
- id: spell-check
exclude: >
(?x)^(
.*\.[rR]|
.*\.feather|
.*\.jpeg|
.*\.pdf|
.*\.png|
.*\.py|
.*\.RData|
.*\.rds|
.*\.Rds|
.*\.Rproj|
.*\.scss|
.*\.sh|
.*\.svg|
.*\.qmd|
(.*/|)\.gitignore|
(.*/|)\.gitlab-ci\.yml|
(.*/|)\.lintr|
(.*/|)\.pre-commit-.*|
(.*/|)\.Rbuildignore|
(.*/|)\.Renviron|
(.*/|)\.Rprofile|
(.*/|)CODEOWNERS|
(.*/|)DESCRIPTION|
(.*/|)LICENSE|
(.*/|)NAMESPACE|
(.*/|)staged_dependencies\.y[a]?ml|
(.*/|)renv/settings\.dcf|
(.*/|)renv\.lock|
(.*/|)WORDLIST|
\.github/workflows/.*|
(.*/|)\_quarto[-]?.*\.yml|
(.*/|)markdown-snaps.md|
data/.*
)$
- id: lintr
- id: parsable-R
- id: no-browser-statement
- id: no-debug-statement
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ['--maxkb=200']
- repo: local
hooks:
- id: forbid-to-commit
name: Don't commit common R artifacts
entry: Cannot commit .Rhistory, .RData, .Rds or .rds.
language: fail
files: '\.(Rhistory|RData|Rds|rds)$'
# `exclude: <regex>` to allow committing specific files
5 changes: 5 additions & 0 deletions book/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ website:
language: en
loading: lazy
mapping: pathname

profile:
group:
- [stable, development]
default: stable
10 changes: 5 additions & 5 deletions book/generate-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ print_ref_templates <- function(fpath) {

section_header <- function(title) {
cat(
paste("", "------------------------------------------------------------------------", "", # nolint
paste("", "------------------------------------------------------------------------", "",
paste0("### ", "**", title, "**"), "",
sep = "\n"
),
Expand All @@ -24,15 +24,15 @@ section_header <- function(title) {
}

create_subsection <- function(fpath, title) {
cat(paste("", paste("####", title), "", "", sep = "\n"), file = "./tlg-index.qmd", append = TRUE) # nolint
cat(paste("", paste("####", title), "", "", sep = "\n"), file = "./tlg-index.qmd", append = TRUE)
all_files <- list.files(path = fpath, pattern = "*.qmd", full.names = TRUE)
invisible(sapply(all_files, print_ref_templates))
}

# Create Index Header

cat(
paste("---", "title: Index", "toc: true", "toc-depth: 4", "---", "", sep = "\n"), # nolint
paste("---", "title: Index", "toc: true", "toc-depth: 4", "---", "", sep = "\n"),
file = "./tlg-index.qmd"
)

Expand Down Expand Up @@ -61,9 +61,9 @@ create_subsection("./tables/vital-signs", "Vital Signs")
section_header("Listings")
create_subsection("./listings/ADA", "ADA")
create_subsection("./listings/adverse-events", "Adverse Events")
create_subsection("./listings/concomitant-medications", "Concomitant Medications") # nolint
create_subsection("./listings/concomitant-medications", "Concomitant Medications")
create_subsection("./listings/disposition", "Disposition")
create_subsection("./listings/development-safety-update-report", "Development Safety Update Report") # nolint
create_subsection("./listings/development-safety-update-report", "Development Safety Update Report")
create_subsection("./listings/ECG", "ECG")
create_subsection("./listings/exposure", "Exposure")
create_subsection("./listings/lab-results", "Lab Results")
Expand Down
25 changes: 15 additions & 10 deletions book/graphs/efficacy/fstg01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ var_labels(anl_rsp_arms_ab) <- c(anl_labels, is_rsp = "Is Responder")

## Standard Plot

```{r plot1, test = list(plot_v1 = "plot"), fig.width = 20, fig.height = 5}
<!-- skip strict because of https://github.com/therneau/survival/issues/240 -->
```{r plot1, test = list(plot_v1 = "plot"), fig.width = 20, fig.height = 5, opts.label = c('skip_test_strict')}
df <- extract_rsp_subgroups(
variables = list(
rsp = "is_rsp",
arm = "ARM",
subgroups = c("SEX", "BMRKR2"),
strata_var = "STRATA2"
strata = "STRATA2"
),
data = anl_rsp_arms_ab,
conf_level = 0.95
Expand All @@ -65,7 +66,8 @@ plot

## Plot Specifying Class Variables and <br/> Options for the Treatment Variable

```{r plot2, test = list(plot_v2 = "plot"), fig.width = 20, fig.height = 5}
<!-- skip strict because of https://github.com/therneau/survival/issues/240 -->
```{r plot2, test = list(plot_v2 = "plot"), fig.width = 20, fig.height = 5, opts.label = c('skip_test_strict')}
anl_rsp_comb_arms_ac <- anl %>%
mutate(is_rsp = AVALC %in% c("CR", "PR")) %>%
filter(ARMCD %in% c("ARM B", "ARM A", "ARM C")) %>%
Expand All @@ -89,7 +91,7 @@ df <- extract_rsp_subgroups(
rsp = "is_rsp",
arm = "ARMCD",
subgroups = c("SEX", "BMRKR2"),
strata_var = "STRATA2"
strata = "STRATA2"
),
data = anl_rsp_comb_arms_ac,
conf_level = 0.95
Expand All @@ -104,13 +106,14 @@ plot

## Plot Selecting Columns and <br/> Changing the Alpha Level

```{r plot3, test = list(plot_v3 = "plot"), fig.width = 10, fig.height = 4}
<!-- skip strict because of https://github.com/therneau/survival/issues/240 -->
```{r plot3, test = list(plot_v3 = "plot"), fig.width = 10, fig.height = 4, opts.label = c('skip_test_strict')}
df <- extract_rsp_subgroups(
variables = list(
rsp = "is_rsp",
arm = "ARM",
subgroups = c("SEX", "BMRKR2"),
strata_var = "STRATA2"
strata = "STRATA2"
),
data = anl_rsp_arms_ab,
conf_level = 0.90
Expand All @@ -125,13 +128,14 @@ plot

## Plot with Fixed <br/> Symbol Size

```{r plot4, test = list(plot_v4 = "plot"), fig.width = 20, fig.height = 5}
<!-- skip strict because of https://github.com/therneau/survival/issues/240 -->
```{r plot4, test = list(plot_v4 = "plot"), fig.width = 20, fig.height = 5, opts.label = c('skip_test_strict')}
df <- extract_rsp_subgroups(
variables = list(
rsp = "is_rsp",
arm = "ARM",
subgroups = c("SEX", "BMRKR2"),
strata_var = "STRATA2"
strata = "STRATA2"
),
data = anl_rsp_arms_ab,
conf_level = 0.95
Expand All @@ -149,7 +153,8 @@ plot

## Plot of CR Only, Setting <br/> Values Indicating Response

```{r plot5, test = list(plot_v5 = "plot"), fig.width = 20, fig.height = 5}
<!-- skip strict because of https://github.com/therneau/survival/issues/240 -->
```{r plot5, test = list(plot_v5 = "plot"), fig.width = 20, fig.height = 5, opts.label = c('skip_test_strict')}
anl_cr_arms_ab <- anl %>%
mutate(is_rsp = AVALC == "CR") %>%
filter(ARMCD %in% c("ARM B", "ARM A")) %>%
Expand All @@ -167,7 +172,7 @@ df <- extract_rsp_subgroups(
rsp = "is_rsp",
arm = "ARM",
subgroups = c("SEX", "BMRKR2"),
strata_var = "STRATA2"
strata = "STRATA2"
),
data = anl_cr_arms_ab,
conf_level = 0.95
Expand Down
2 changes: 1 addition & 1 deletion book/graphs/efficacy/fstg02.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ plot
```{r test parameters, test = list(width = "width", height = "height", plot_v3.width = "plot_v3.width"), echo=FALSE}
width <- 15
height <- 4
plot_v3.width <- 8
plot_v3.width <- 8 # nolint: object_name.
```

{{< include ../../test-utils/save_results.qmd >}}
Expand Down
18 changes: 12 additions & 6 deletions book/graphs/efficacy/kmg01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ variables <- list(tte = "AVAL", is_event = "is_event", arm = "ARMCD")

## Standard Plot

```{r plot1, fig.height=8, test = list(plot_v1 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot1, fig.height=8, test = list(plot_v1 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_km(
df = anl,
variables = variables,
Expand All @@ -40,7 +41,8 @@ plot

## Plot of Failures

```{r plot2, fig.height=8, test = list(plot_v2 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot2, fig.height=8, test = list(plot_v2 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_km(
df = anl,
variables = variables,
Expand All @@ -58,7 +60,8 @@ plot

## Plot Without <br/> Comparative Statistics

```{r plot3, fig.height=8, test = list(plot_v3 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot3, fig.height=8, test = list(plot_v3 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_km(
df = anl,
variables = variables,
Expand All @@ -71,7 +74,8 @@ plot

## Plot Without <br/> Censoring Marks

```{r plot4, fig.height=8, test = list(plot_v4 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot4, fig.height=8, test = list(plot_v4 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_km(
df = anl,
variables = variables,
Expand All @@ -85,7 +89,8 @@ plot

## Plot Modifying <br/> Censoring Marks

```{r plot5, fig.height=8, test = list(plot_v5 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot5, fig.height=8, test = list(plot_v5 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_km(
df = anl,
variables = variables,
Expand All @@ -100,7 +105,8 @@ plot

## Plot Modifying Options for Statistics, <br/> Tie Handling, Stratification, etc.

```{r plot6, test = list(plot_v6 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot6, test = list(plot_v6 = "plot"), opts.label = c('skip_test_strict')}
variables$strata <- c("STRATA1", "STRATA2")
plot <- g_km(
df = anl,
Expand Down
12 changes: 8 additions & 4 deletions book/graphs/efficacy/mmrmg01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ mmrm_results <- fit_mmrm(

### Considering the treatment variable in the model

```{r plot1, dev.args=list(pointsize=6), test = list(plot_v1 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot1, dev.args=list(pointsize=6), test = list(plot_v1 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_mmrm_lsmeans(
mmrm_results,
select = "estimates",
Expand All @@ -57,7 +58,8 @@ plot

### Considering the treatment variable in the model, with lines

```{r plot2, dev.args=list(pointsize=6), test = list(plot_v2 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot2, dev.args=list(pointsize=6), test = list(plot_v2 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_mmrm_lsmeans(
mmrm_results,
select = "estimates",
Expand All @@ -69,7 +71,8 @@ plot

### Considering the treatment variable in the model, with statistics table

```{r plot3, dev.args=list(pointsize=6), fig.height=7, test = list(plot_v3 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot3, dev.args=list(pointsize=6), fig.height=7, test = list(plot_v3 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_mmrm_lsmeans(
mmrm_results,
select = "estimates",
Expand All @@ -85,7 +88,8 @@ plot

Users can choose to display both estimates and contrasts together by running `g_mmrm_lsmeans(mmrm_results)`.

```{r plot4, dev.args=list(pointsize=6), test = list(plot_v4 = "plot")}
<!-- skip strict because of https://github.com/r-lib/gtable/pull/94 -->
```{r plot4, dev.args=list(pointsize=6), test = list(plot_v4 = "plot"), opts.label = c('skip_test_strict')}
plot <- g_mmrm_lsmeans(
mmrm_results,
select = "contrasts",
Expand Down
2 changes: 1 addition & 1 deletion book/graphs/efficacy/mmrmg02.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ adqs_f <- adqs %>%
set.seed(2)
adqs_f_with_groups <- rbind(
within(
adqs_f[sample(1:nrow(adqs_f), size = 1 / 2 * nrow(adqs_f)), ],
adqs_f[sample(seq_len(nrow(adqs_f)), size = 1 / 2 * nrow(adqs_f)), ],
group <- "subpopulation 1"
),
within(
Expand Down
Loading

0 comments on commit d17033f

Please sign in to comment.