Skip to content

Commit c3c6550

Browse files
authored
Adding a basic formatter CI and the empty renv (#4)
* Adding a basic formatter CI and the empty renv * adding lintr CI * Installing cyclocomp * Fixing lint errors * linting fixes
1 parent 721452e commit c3c6550

File tree

11 files changed

+1535
-20
lines changed

11 files changed

+1535
-20
lines changed

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
^renv$
2+
^renv\.lock$
3+
^\.github$

.Rprofile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source("renv/activate.R")

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples
2+
3+
on:
4+
# Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN`
5+
# privileges, otherwise we can't set `pull-requests: write` when the pull
6+
# request comes from a fork, which is our main use case (external contributors).
7+
#
8+
# `pull_request_target` runs in the context of the target branch (`main`, usually),
9+
# rather than in the context of the pull request like `pull_request` does. Due
10+
# to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`.
11+
# This is typically frowned upon by GitHub, as it exposes you to potentially running
12+
# untrusted code in a context where you have elevated privileges, but they explicitly
13+
# call out the use case of reformatting and committing back / commenting on the PR
14+
# as a situation that should be safe (because we aren't actually running the untrusted
15+
# code, we are just treating it as passive data).
16+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
17+
pull_request_target:
18+
19+
name: format-suggest.yml
20+
21+
jobs:
22+
format-suggest:
23+
name: format-suggest
24+
runs-on: ubuntu-latest
25+
26+
permissions:
27+
# Required to push suggestion comments to the PR
28+
pull-requests: write
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.pull_request.head.sha }}
34+
35+
- name: Install
36+
uses: posit-dev/setup-air@v1
37+
38+
- name: Format
39+
run: air format .
40+
41+
- name: Suggest
42+
uses: reviewdog/action-suggester@v1
43+
with:
44+
level: error
45+
fail_level: error
46+
tool_name: air

.github/workflows/lint-project.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
push:
5+
branches: [main, master]
6+
pull_request:
7+
8+
name: lint-project.yml
9+
10+
permissions: read-all
11+
12+
jobs:
13+
lint-project:
14+
runs-on: ubuntu-latest
15+
env:
16+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: r-lib/actions/setup-r@v2
21+
with:
22+
use-public-rspm: true
23+
24+
- name: Install lintr
25+
run: install.packages("lintr")
26+
shell: Rscript {0}
27+
28+
- name: Install cyclocomp
29+
run: install.packages("cyclocomp")
30+
shell: Rscript {0}
31+
32+
- name: Lint root directory
33+
run: lintr::lint_dir()
34+
shell: Rscript {0}
35+
env:
36+
LINTR_ERROR_ON_LINT: true

.lintr

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
################################################################################
2-
## File: .lintr ##
3-
## Project: msm-nida-ctn ##
4-
## Created Date: 2025-08-28 ##
5-
## Author: Matthew Carroll ##
6-
## ----- ##
7-
## Last Modified: 2025-11-05 ##
8-
## Modified By: Dimitri Baptiste ##
9-
## ----- ##
10-
## Copyright (c) 2025 Syndemics Lab at Boston Medical Center ##
11-
################################################################################
12-
131
linters: all_linters(
142
assignment_linter = assignment_linter(operator = c("<-"), allow_trailing = FALSE),
153
backport_linter = backport_linter("4.0.0"),
@@ -19,8 +7,14 @@ linters: all_linters(
197
object_name_linter = object_name_linter(styles = c("snake_case", "lowercase")),
208
return_linter = return_linter(return_style = "explicit", allow_implicit_else = FALSE),
219
cyclocomp_linter = cyclocomp_linter(complexity_limit = 10L),
22-
object_usage_linter = object_usage_linter(interpret_glue = TRUE),
2310
unused_import_linter = unused_import_linter(interpret_glue = TRUE),
11+
undesirable_function_linter = undesirable_function_linter(
12+
fun = modify_defaults(
13+
defaults = default_undesirable_functions,
14+
source = NULL,
15+
library = NULL,
16+
require = NULL)),
17+
object_usage_linter = NULL, # This doesn't work well with dplyr
2418
condition_call_linter = NULL,
2519
condition_message_linter = NULL,
2620
consecutive_mutate_linter = NULL,

R/utils.R

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@
2323
#' @examples
2424
#' ensure_packages(c("dplyr", "here"))
2525
ensure_packages <- function(packages) {
26-
sapply(packages, function(package) {
27-
if (!(package %in% rownames(installed.packages()))) {
28-
install.packages(package, repos = "http://cran.us.r-project.org")
29-
}
30-
library(package, character.only = TRUE, warn.conflicts = FALSE)
31-
return(require(package, character.only = TRUE))
32-
})
26+
return(vapply(
27+
packages,
28+
function(package) {
29+
if (!(package %in% rownames(installed.packages()))) {
30+
install.packages(
31+
package,
32+
repos = "http://cran.us.r-project.org"
33+
)
34+
}
35+
library(package, character.only = TRUE, warn.conflicts = FALSE)
36+
return(require(package, character.only = TRUE))
37+
},
38+
logical(length(packages))
39+
))
3340
}

renv.lock

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"R": {
3+
"Version": "4.5.2",
4+
"Repositories": [
5+
{
6+
"Name": "CRAN",
7+
"URL": "https://cloud.r-project.org"
8+
}
9+
]
10+
},
11+
"Packages": {
12+
"renv": {
13+
"Package": "renv",
14+
"Version": "1.1.5",
15+
"Source": "Repository",
16+
"Type": "Package",
17+
"Title": "Project Environments",
18+
"Authors@R": "c( person(\"Kevin\", \"Ushey\", role = c(\"aut\", \"cre\"), email = \"kevin@rstudio.com\", comment = c(ORCID = \"0000-0003-2880-7407\")), person(\"Hadley\", \"Wickham\", role = c(\"aut\"), email = \"hadley@rstudio.com\", comment = c(ORCID = \"0000-0003-4757-117X\")), person(\"Posit Software, PBC\", role = c(\"cph\", \"fnd\")) )",
19+
"Description": "A dependency management toolkit for R. Using 'renv', you can create and manage project-local R libraries, save the state of these libraries to a 'lockfile', and later restore your library as required. Together, these tools can help make your projects more isolated, portable, and reproducible.",
20+
"License": "MIT + file LICENSE",
21+
"URL": "https://rstudio.github.io/renv/, https://github.com/rstudio/renv",
22+
"BugReports": "https://github.com/rstudio/renv/issues",
23+
"Imports": [
24+
"utils"
25+
],
26+
"Suggests": [
27+
"BiocManager",
28+
"cli",
29+
"compiler",
30+
"covr",
31+
"cpp11",
32+
"devtools",
33+
"generics",
34+
"gitcreds",
35+
"jsonlite",
36+
"jsonvalidate",
37+
"knitr",
38+
"miniUI",
39+
"modules",
40+
"packrat",
41+
"pak",
42+
"R6",
43+
"remotes",
44+
"reticulate",
45+
"rmarkdown",
46+
"rstudioapi",
47+
"shiny",
48+
"testthat",
49+
"uuid",
50+
"waldo",
51+
"yaml",
52+
"webfakes"
53+
],
54+
"Encoding": "UTF-8",
55+
"RoxygenNote": "7.3.2",
56+
"VignetteBuilder": "knitr",
57+
"Config/Needs/website": "tidyverse/tidytemplate",
58+
"Config/testthat/edition": "3",
59+
"Config/testthat/parallel": "true",
60+
"Config/testthat/start-first": "bioconductor,python,install,restore,snapshot,retrieve,remotes",
61+
"NeedsCompilation": "no",
62+
"Author": "Kevin Ushey [aut, cre] (ORCID: <https://orcid.org/0000-0003-2880-7407>), Hadley Wickham [aut] (ORCID: <https://orcid.org/0000-0003-4757-117X>), Posit Software, PBC [cph, fnd]",
63+
"Maintainer": "Kevin Ushey <kevin@rstudio.com>",
64+
"Repository": "CRAN"
65+
}
66+
}
67+
}

renv/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
library/
2+
local/
3+
cellar/
4+
lock/
5+
python/
6+
sandbox/
7+
staging/

0 commit comments

Comments
 (0)