Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^renv$
^renv\.lock$
^\.github$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
46 changes: 46 additions & 0 deletions .github/workflows/format-suggest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples

on:
# Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN`
# privileges, otherwise we can't set `pull-requests: write` when the pull
# request comes from a fork, which is our main use case (external contributors).
#
# `pull_request_target` runs in the context of the target branch (`main`, usually),
# rather than in the context of the pull request like `pull_request` does. Due
# to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`.
# This is typically frowned upon by GitHub, as it exposes you to potentially running
# untrusted code in a context where you have elevated privileges, but they explicitly
# call out the use case of reformatting and committing back / commenting on the PR
# as a situation that should be safe (because we aren't actually running the untrusted
# code, we are just treating it as passive data).
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
pull_request_target:

name: format-suggest.yml

jobs:
format-suggest:
name: format-suggest
runs-on: ubuntu-latest

permissions:
# Required to push suggestion comments to the PR
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install
uses: posit-dev/setup-air@v1

- name: Format
run: air format .

- name: Suggest
uses: reviewdog/action-suggester@v1
with:
level: error
fail_level: error
tool_name: air
36 changes: 36 additions & 0 deletions .github/workflows/lint-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: lint-project.yml

permissions: read-all

jobs:
lint-project:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install lintr
run: install.packages("lintr")
shell: Rscript {0}

- name: Install cyclocomp
run: install.packages("cyclocomp")
shell: Rscript {0}

- name: Lint root directory
run: lintr::lint_dir()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
20 changes: 7 additions & 13 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
################################################################################
## File: .lintr ##
## Project: msm-nida-ctn ##
## Created Date: 2025-08-28 ##
## Author: Matthew Carroll ##
## ----- ##
## Last Modified: 2025-11-05 ##
## Modified By: Dimitri Baptiste ##
## ----- ##
## Copyright (c) 2025 Syndemics Lab at Boston Medical Center ##
################################################################################

linters: all_linters(
assignment_linter = assignment_linter(operator = c("<-"), allow_trailing = FALSE),
backport_linter = backport_linter("4.0.0"),
Expand All @@ -19,8 +7,14 @@ linters: all_linters(
object_name_linter = object_name_linter(styles = c("snake_case", "lowercase")),
return_linter = return_linter(return_style = "explicit", allow_implicit_else = FALSE),
cyclocomp_linter = cyclocomp_linter(complexity_limit = 10L),
object_usage_linter = object_usage_linter(interpret_glue = TRUE),
unused_import_linter = unused_import_linter(interpret_glue = TRUE),
undesirable_function_linter = undesirable_function_linter(
fun = modify_defaults(
defaults = default_undesirable_functions,
source = NULL,
library = NULL,
require = NULL)),
object_usage_linter = NULL, # This doesn't work well with dplyr
condition_call_linter = NULL,
condition_message_linter = NULL,
consecutive_mutate_linter = NULL,
Expand Down
21 changes: 14 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@
#' @examples
#' ensure_packages(c("dplyr", "here"))
ensure_packages <- function(packages) {
sapply(packages, function(package) {
if (!(package %in% rownames(installed.packages()))) {
install.packages(package, repos = "http://cran.us.r-project.org")
}
library(package, character.only = TRUE, warn.conflicts = FALSE)
return(require(package, character.only = TRUE))
})
return(vapply(
packages,
function(package) {
if (!(package %in% rownames(installed.packages()))) {
install.packages(
package,
repos = "http://cran.us.r-project.org"
)
}
library(package, character.only = TRUE, warn.conflicts = FALSE)
return(require(package, character.only = TRUE))
},
logical(length(packages))
))
}
67 changes: 67 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"R": {
"Version": "4.5.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.1.5",
"Source": "Repository",
"Type": "Package",
"Title": "Project Environments",
"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\")) )",
"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.",
"License": "MIT + file LICENSE",
"URL": "https://rstudio.github.io/renv/, https://github.com/rstudio/renv",
"BugReports": "https://github.com/rstudio/renv/issues",
"Imports": [
"utils"
],
"Suggests": [
"BiocManager",
"cli",
"compiler",
"covr",
"cpp11",
"devtools",
"generics",
"gitcreds",
"jsonlite",
"jsonvalidate",
"knitr",
"miniUI",
"modules",
"packrat",
"pak",
"R6",
"remotes",
"reticulate",
"rmarkdown",
"rstudioapi",
"shiny",
"testthat",
"uuid",
"waldo",
"yaml",
"webfakes"
],
"Encoding": "UTF-8",
"RoxygenNote": "7.3.2",
"VignetteBuilder": "knitr",
"Config/Needs/website": "tidyverse/tidytemplate",
"Config/testthat/edition": "3",
"Config/testthat/parallel": "true",
"Config/testthat/start-first": "bioconductor,python,install,restore,snapshot,retrieve,remotes",
"NeedsCompilation": "no",
"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]",
"Maintainer": "Kevin Ushey <kevin@rstudio.com>",
"Repository": "CRAN"
}
}
}
7 changes: 7 additions & 0 deletions renv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library/
local/
cellar/
lock/
python/
sandbox/
staging/
Loading