Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting to CI and style code #19

Merged
merged 14 commits into from
Aug 14, 2024
Merged
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ $run_dev.*
^.here$
^LICENSE\.md$
^\.github$
^\.lintr$
9 changes: 5 additions & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ jobs:
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/setup-renv@v2

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

- uses: r-lib/actions/check-r-package@v2
with:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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:
branches: [main, master]

name: lint.yaml

permissions: read-all

jobs:
lint:
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

- uses: r-lib/actions/setup-renv@v2

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

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
86 changes: 86 additions & 0 deletions .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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:
issue_comment:
types: [created]

name: pr-commands.yaml

permissions: read-all

jobs:
document:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }}
name: document
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

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

- uses: r-lib/actions/setup-renv@v2

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

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add man/\* NAMESPACE
git commit -m 'Document'

- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

style:
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }}
name: style
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-r@v2

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

- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: commit
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add \*.R
git commit -m 'Style'

- uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters: linters_with_defaults(
line_length_linter(120),
object_name_linter(styles = c("snake_case", "symbols", "camelCase"))
)
encoding: "UTF-8"
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Suggests:
usethis,
styler,
testthat (>= 3.0.0),
spelling
spelling,
lintr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Expand Down
23 changes: 11 additions & 12 deletions R/app_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ app_sys <- function(...) {
#'
#' @noRd
get_golem_config <- function(
value,
config = Sys.getenv(
"GOLEM_CONFIG_ACTIVE",
Sys.getenv(
"R_CONFIG_ACTIVE",
"default"
)
),
use_parent = TRUE,
# Modify this if your config file is somewhere else
file = app_sys("golem-config.yml")
) {
value,
config = Sys.getenv(
"GOLEM_CONFIG_ACTIVE",
Sys.getenv(
"R_CONFIG_ACTIVE",
"default"
)
),
use_parent = TRUE,
# Modify this if your config file is somewhere else
file = app_sys("golem-config.yml")) {
config::get(
value = value,
config = config,
Expand Down
3 changes: 1 addition & 2 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
#' @import shiny
#' @noRd
app_server <- function(input, output, session) {

# TODO: to be replaced by real data, which should be reactive so it responds to filtering options
mock_data <- data.frame(
concept_id = c(2212648, 2617206, 2212406),
name = c(
"Blood count; complete (CBC), automated (Hgb, Hct, RBC, WBC and platelet count) and automated differential WBC count",
"Blood count; complete (CBC), automated (Hgb, Hct, RBC, WBC and platelet count) and automated differential WBC count", # nolint
"Prostate specific antigen test (psa)",
"Homocysteine"
),
person_count = c(7080, 960, 10),
records_per_person = c(4.37, 1.12, 1.06)
)
mock_data <- reactiveVal(mock_data)

Check warning on line 19 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=19,col=16,[object_usage_linter] no visible global function definition for 'reactiveVal'

selected_data <- mod_select_concepts_server("select_concepts", mock_data)

Check warning on line 21 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=21,col=20,[object_usage_linter] no visible global function definition for 'mod_select_concepts_server'

mod_date_range_server("date_range_1")

Check warning on line 23 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=23,col=3,[object_usage_linter] no visible global function definition for 'mod_date_range_server'
mod_datatable_server("totals", selected_data)

Check warning on line 24 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=24,col=3,[object_usage_linter] no visible global function definition for 'mod_datatable_server'
mod_monthly_count_server("monthly_count_1")

Check warning on line 25 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=25,col=3,[object_usage_linter] no visible global function definition for 'mod_monthly_count_server'
mod_stat_numeric_server("stat_numeric_1")

Check warning on line 26 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=26,col=3,[object_usage_linter] no visible global function definition for 'mod_stat_numeric_server'
mod_export_tab_server("export_tab", selected_data)

Check warning on line 27 in R/app_server.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_server.R,line=27,col=3,[object_usage_linter] no visible global function definition for 'mod_export_tab_server'
}
10 changes: 4 additions & 6 deletions R/mod_daterange.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mod_date_range_ui <- function(id) {
format = "yyyy-mm",
),
sliderInput(ns("slider"), "Date range:",
min = as.Date("2019-04-01", "%Y-%m-%d"),
max = as.Date("2024-08-01", "%Y-%m-%d"),
value = c(as.Date("2019-04-01"), as.Date("2024-08-01")),
timeFormat = "%Y-%m"
min = as.Date("2019-04-01", "%Y-%m-%d"),
max = as.Date("2024-08-01", "%Y-%m-%d"),
value = c(as.Date("2019-04-01"), as.Date("2024-08-01")),
timeFormat = "%Y-%m"
)
)
}
Expand All @@ -32,7 +32,5 @@ mod_date_range_ui <- function(id) {
#' @noRd
mod_date_range_server <- function(id) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
})
}

4 changes: 2 additions & 2 deletions R/mod_monthly_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_monthly_count_ui <- function(id){
mod_monthly_count_ui <- function(id) {
ns <- NS(id)
tagList(
plotOutput(ns("monthly_count_plot"), height = 250)
Expand All @@ -23,7 +23,7 @@ mod_monthly_count_server <- function(id) {
# Need to get the input data and filter it based on the selected timeframe and selected row
# see https://stackoverflow.com/a/77039776/11801854
monthly_count <- data.frame(
date = c("2020-01","2020-02", "2020-03", "2020-04"),
date = c("2020-01", "2020-02", "2020-03", "2020-04"),
record_count = c(120, 250, 281, 220)
)
output$monthly_count_plot <- renderPlot({
Expand Down
11 changes: 5 additions & 6 deletions R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#' @importFrom shiny shinyApp
#' @importFrom golem with_golem_options
run_app <- function(
onStart = NULL,
options = list(),
enableBookmarking = NULL,
uiPattern = "/",
...
) {
onStart = NULL,
options = list(),
enableBookmarking = NULL,
uiPattern = "/",
...) {
with_golem_options(
app = shinyApp(
ui = app_ui,
Expand Down
Loading
Loading