Skip to content

Commit

Permalink
Adds and runs extended pre-commit (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikSpiegel authored Feb 29, 2024
1 parent e9f9533 commit ea74812
Show file tree
Hide file tree
Showing 23 changed files with 121 additions and 57 deletions.
7 changes: 4 additions & 3 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
^chef\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^\.Rproj\.user$
^\.github$
^\.pre-commit-config\.yaml$
^_pkgdown\.yml$
^chef\.Rproj$
^docs$
^pkgdown$
^\.github$
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ for branch in "${protected_branches[@]}"; do
done


exit 0
exit 0
1 change: 0 additions & 1 deletion .github/workflows/Check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ jobs:
# uses: ./.github/workflows/Roxygen.yaml



2 changes: 1 addition & 1 deletion .github/workflows/PR_cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
steps:
- uses: stefanluptak/delete-old-pr-artifacts@v1
with:
workflow_filename: Check.yaml
workflow_filename: Check.yaml
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
upload-snapshots: true
2 changes: 1 addition & 1 deletion .github/workflows/Roxygen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@
}
fi
shell: bash
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
2 changes: 1 addition & 1 deletion .github/workflows/Test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
path: ${{ runner.temp }}/package
76 changes: 76 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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.3.2.9027
hooks:
# - id: style-files
# args: [--style_pkg=styler, --style_fun=tidyverse_style]
# - id: roxygenize
# codemeta must be above use-tidy-description when both are used
# - id: codemeta-description-updated
# - id: use-tidy-description
# - id: spell-check
# exclude: >
# (?x)^(
# .*\.[rR]|
# .*\.feather|
# .*\.jpeg|
# .*\.pdf|
# .*\.png|
# .*\.py|
# .*\.RData|
# .*\.rds|
# .*\.Rds|
# .*\.Rproj|
# .*\.sh|
# (.*/|)\.gitignore|
# (.*/|)\.gitlab-ci\.yml|
# (.*/|)\.lintr|
# (.*/|)\.pre-commit-.*|
# (.*/|)\.Rbuildignore|
# (.*/|)\.Renviron|
# (.*/|)\.Rprofile|
# (.*/|)\.travis\.yml|
# (.*/|)appveyor\.yml|
# (.*/|)NAMESPACE|
# (.*/|)renv/settings\.dcf|
# (.*/|)renv\.lock|
# (.*/|)WORDLIST|
# \.github/workflows/.*|
# data/.*|
# )$
# - id: lintr
- id: readme-rmd-rendered
- id: parsable-R
- id: no-browser-statement
- id: no-print-statement
- id: no-debug-statement
exclude: "R/try_and_validate.R"
- id: deps-in-desc
args: [--allow_private_imports]
exclude: "tests/testthat/test-fetch_db_data.R"
- id: pkgdown
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: no-commit-to-branch
args: [--branch, staging, --branch, main, --branch, dev]
- id: check-added-large-files
args: ['--maxkb=200']
# - id: file-contents-sorter
# files: '^\.Rbuildignore$'
- id: end-of-file-fixer
exclude: >
'\.Rd'
'tests/testthat/_snaps'
- id: detect-private-key
# - id: detect-aws-credentials
- 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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Imports:
tarchetypes,
usethis,
utils,
crew
crew,
purrr
Suggests:
covr,
fs,
Expand All @@ -53,4 +54,3 @@ Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1

2 changes: 0 additions & 2 deletions R/apply_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,3 @@ apply_stats <-
ep_cp[, .SD, .SDcols = keep]

}


3 changes: 0 additions & 3 deletions R/mk_userdef_fn_dt.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,3 @@ generate_function_table_row <- function(fn_type, fn, fn_name, fn_hash, env){

return(out_row)
}



1 change: 0 additions & 1 deletion R/validate_endpoints_def.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,3 @@ error_not_fn <- function(x, i) {
)
}
}

16 changes: 14 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ Behind the scenes, {chef} uses the {[targets](https://books.ropensci.org/targets

## Install githooks

```
This project supports two styles of githooks.

1. The first style is to use the githooks provided in the `.githooks` directory. To use these hooks, run the following command in the root of the project:
- These hooks are very simple just blocking the commit to protected branches.
``
git config --local core.hooksPath .githooks/
```
```
2. The second is to install the precommit tool (for linux) [precommit](https://pre-commit.com/).
- These are much more powerful and can be used to run checks on the code before it is committed.
```
pipx install pre-commit
# Then run in the root of repo:
pre-commit install
```
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

<!-- Insert badges here -->

[![R-CMD-check](https://github.com/hta-pharma/chef/actions/workflows/package-check-test.yaml/badge.svg)](https://github.com/hta-pharma/chef/actions/workflows/package-check-test.yaml)
<!-- README.md is generated from README.Rmd. Please edit that file -->

# chef
Expand Down Expand Up @@ -37,4 +40,20 @@ pipelines.

## Install githooks

git config --local core.hooksPath .githooks/
This project supports two styles of githooks.

1. The first style is to use the githooks provided in the `.githooks`
directory. To use these hooks, run the following command in the root
of the project:

- These hooks are very simple just blocking the commit to protected
branches. \`\` git config –local core.hooksPath .githooks/

<!-- -->


2. The second is to install the precommit tool (for linux) [precommit](https://pre-commit.com/).
- These are much more powerful and can be used to run checks on the code before it is committed.

pipx install pre-commit \# Then run in the root of repo: pre-commit
install \`\`\`
1 change: 0 additions & 1 deletion tests/testthat/_snaps/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,3 @@
10: SEX == "M"... 1-0001-000... 4, 5, 6, 7,45,46,... <data.table[1x4]>
11: SEX == "F"... 1-0001-000... 11,12,54,55,56,57,... <data.table[1x4]>
12: SEX == "M"... 1-0001-000... 8, 9,70,71,72,73,... <data.table[1x4]>

1 change: 0 additions & 1 deletion tests/testthat/helper-custom_expect.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ expect_same_items <- function(actual, expected, ...) {
}
invisible(actual)
}

1 change: 0 additions & 1 deletion tests/testthat/test-apply_criterion_by_strata.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,3 @@ test_that("strata_var remains a character variable when some endpoint have been
expect_equal(typeof(actual[["strata_var"]]), "character")

})

1 change: 0 additions & 1 deletion tests/testthat/test-apply_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,3 @@ test_that("Complex application of stats functions",
expect_true(all(ep_stat[ep_stat$fn_type == "stat_across_strata_across_trt"][["value"]] == 158))

})

2 changes: 0 additions & 2 deletions tests/testthat/test-prepare_for_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -464,5 +464,3 @@ test_that("base - dataprep", {
regexp = "'arg' should be one of"
)
})


1 change: 0 additions & 1 deletion tests/testthat/test-unnest_endpoint_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,3 @@ test_that("Unnest adam and adsl functions", {
return(x[["fn_type"]] == lookup[[x[["fn_name"]]]])
})), TRUE)
})

2 changes: 0 additions & 2 deletions vignettes/ep_overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,3 @@ The parameters of each endpoint specification can be grouped in to the sets belo
<td>`stat_across_strata_across_trt`</td>
</tr>
</table>


5 changes: 0 additions & 5 deletions vignettes/methods_criteria.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,3 @@ endpoint_XYZ <- mk_endpoint_str(
)
```





23 changes: 0 additions & 23 deletions vignettes/methods_stat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -543,26 +543,3 @@ mk_endpoint_def <- function() {
)
}
```























0 comments on commit ea74812

Please sign in to comment.