Skip to content

Commit

Permalink
Merge branch 'update-function-flow' of https://github.com/steno-aarhu…
Browse files Browse the repository at this point in the history
…s/osdc into update-function-flow
  • Loading branch information
Anders Aasted Isaksen authored and Anders Aasted Isaksen committed Sep 20, 2024
2 parents 7525b60 + 9a74ea0 commit 25db86d
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 78 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/assign-author-to-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Assign author to their PR

on:
pull_request:
types:
- reopened
- opened

permissions:
pull-requests: write

jobs:
assign-author-to-pr:
runs-on: ubuntu-latest
steps:
- name: Assign PR to author
run: |
gh pr edit $PR --add-assignee $AUTHOR
env:
AUTHOR: ${{ github.event.pull_request.user.login }}
PR: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

16 changes: 0 additions & 16 deletions .github/workflows/auto-author-assign.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/puml-to-svg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Generate SVG from PlantUML

on:
pull_request:
paths:
- '**.puml'

jobs:
generate-plantuml:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: plantuml
id: plantuml
uses: grassedge/[email protected]
with:
message: "chore: :bento: (re-)generate `.svg` from `.puml` files"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Suggests:
tibble,
data.table,
arrow,
duckdb
duckplyr
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
2 changes: 2 additions & 0 deletions R/columns-to-lower.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#' @keywords internal
#'
#' @examples
#' \dontrun{
#' tibble::tibble(A = 1:3, B = 4:6) |>
#' osdc:::column_names_to_lower()
#' }
column_names_to_lower <- function(data) {
data |>
dplyr::rename_with(tolower)
Expand Down
8 changes: 6 additions & 2 deletions R/get-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#' @keywords internal
#'
#' @examples
#' osdc:::get_register_abbrev()
#' \dontrun{
#' get_register_abbrev()
#' }
get_register_abbrev <- function() {
unique(variable_description$register_abbrev)
}
Expand All @@ -19,7 +21,9 @@ get_register_abbrev <- function() {
#' @keywords internal
#'
#' @examples
#' osdc:::get_required_variables("bef")
#' \dontrun{
#' get_required_variables("bef")
#' }
get_required_variables <- function(register) {
if (!checkmate::test_scalar(register)) {
cli::cli_abort("You are giving too many registers, please give only one.")
Expand Down
4 changes: 4 additions & 0 deletions R/joins.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#' @keywords internal
#'
#' @examples
#' \dontrun{
#' register_data$lpr_adm |>
#' join_lpr2(register_data$lpr_diag)
#' }
join_lpr2 <- function(lpr_adm, lpr_diag) {
verify_required_variables(lpr_adm, "lpr_adm")
verify_required_variables(lpr_diag, "lpr_diag")
Expand All @@ -28,8 +30,10 @@ join_lpr2 <- function(lpr_adm, lpr_diag) {
#' @keywords internal
#'
#' @examples
#' \dontrun{
#' register_data$kontakter |>
#' join_lpr3(register_data$diagnoser)
#' }
join_lpr3 <- function(kontakter, diagnoser) {
verify_required_variables(kontakter, "kontakter")
verify_required_variables(diagnoser, "diagnoser")
Expand Down
4 changes: 3 additions & 1 deletion R/verify-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#' @keywords internal
#'
#' @examples
#' \dontrun{
#' # TODO: Replace with simulated data.
#' verify_required_variables(register_data$bef, "bef")
#' verify_required_variables(register_data$lpr_adm, "lpr_adm")
#' }
verify_required_variables <- function(data, register, call = rlang::caller_env()) {
checkmate::assert_choice(register, get_register_abbrev())
expected_variables <- sort(get_required_variables(register))
actual_variables <- sort(colnames(data))
actual_variables <- tolower(sort(colnames(data)))

if (!checkmate::test_names(
x = actual_variables,
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# osdc: Open Source Diabetes Classifier for Danish Registers
# osdc <a href="https://steno-aarhus.github.io/osdc/"><img src="man/figures/logo.png" align="right" height="100"/></a>

<!-- badges: start -->

Expand All @@ -8,14 +8,16 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h

<!-- badges: end -->

The goal of *osdc* is to expose an algorithm for classifying diabetes
within the Danish registers that can be accessible as an R package. The
algorithm that has been developed at Steno Diabetes Center Aarhus is
flexible and convenient to use, and validated in terms of accuracy.
While there are a few algorithms used throughout Denmark for Danish
register research, they are usually textual descriptions of how to do
it, rather than code-based descriptions (e.g. the [Register of Selected
Chronic
## Overview

The goal of osdc (**O**pen **S**ource **D**iabetes **C**lassifier) is to
expose an algorithm for classifying diabetes within the Danish registers
that can be accessible as an R package. The algorithm that has been
developed at Steno Diabetes Center Aarhus is flexible and convenient to
use, and validated in terms of accuracy. While there are a few
algorithms used throughout Denmark for Danish register research, they
are usually textual descriptions of how to do it, rather than code-based
descriptions (e.g. the [Register of Selected Chronic
Diseases](https://www.esundhed.dk/-/media/Files/Publikationer/Emner/Operationer-og-diagnoser/Udvalgte-kroniske-sygdomme-svaere-psykiske-lidelser/Algoritmer-for-Udvalgte-Kroniske-Sygdomme-og-svre-psykiske-lidelser-RUKS-2022.ashx)).

In this project, we aim to make it easier and more explicit to classify
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ polycystic
pseudonymised
reproducibility
semaglutid
traceback
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@_default:
just --list --unsorted

# Generate PNG images from all PlantUML files
# Generate svg images from all PlantUML files
generate-puml-all:
docker run --rm -v $(pwd):/puml -w /puml ghcr.io/plantuml/plantuml:1.2024.3 -tpng "**/*.puml"
docker run --rm -v $(pwd):/puml -w /puml ghcr.io/plantuml/plantuml:1.2024.3 -tsvg "**/*.puml"

# Generate PNG image from specific PlantUML file
# Generate svg image from specific PlantUML file
generate-puml name:
docker run --rm -v $(pwd):/puml -w /puml ghcr.io/plantuml/plantuml:1.2024.3 -tpng "**/{{name}}.puml"
docker run --rm -v $(pwd):/puml -w /puml ghcr.io/plantuml/plantuml:1.2024.3 -tsvg "**/{{name}}.puml"
2 changes: 2 additions & 0 deletions man/column_names_to_lower.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion man/get_register_abbrev.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/get_required_variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions man/join_lpr2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions man/join_lpr3.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/verify_required_variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions tests/testthat/helper-options.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# There is a warning when using Arrow about using pull. It says to set
# this option.
options(arrow.pull_as_vector = TRUE)
options(
# There is a warning when using Arrow about using pull. It says to set
# this option.
arrow.pull_as_vector = TRUE,
# DuckDB outputs a lot of messages, this stops that.
duckdb.materialize_message = FALSE
)
# By default, duckplyr logs messages and outputs them when it runs.
# Adding these options so the test output looks cleaner.
Sys.setenv(DUCKPLYR_FALLBACK_COLLECT = 0)
Sys.setenv(DUCKPLYR_FALLBACK_VERBOSE = FALSE)
8 changes: 7 additions & 1 deletion tests/testthat/test-columns-to-lower.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ test_that("columns are correctly converted to lowercase", {
})

test_that("columns are converted for DuckDB Database", {
actual <- arrow::to_duckdb(data) |>
skip_on_cran()
skip_if_not_installed("duckplyr")
actual <- duckplyr::as_duckplyr_tibble(data) |>
column_names_to_lower() |>
# DuckDB needs to use `colnames()`
colnames()
Expand All @@ -24,6 +26,8 @@ test_that("columns are converted for DuckDB Database", {
})

test_that("columns are converted for Arrow Tables (from Parquet)", {
skip_on_cran()
skip_if_not_installed("arrow")
actual <- arrow::as_arrow_table(data) |>
column_names_to_lower() |>
names()
Expand All @@ -40,6 +44,8 @@ test_that("columns are converted for data.frame", {
})

test_that("columns are converted for data.table", {
skip_on_cran()
skip_if_not_installed("data.table")
actual <- data.table::as.data.table(data) |>
column_names_to_lower() |>
names()
Expand Down
8 changes: 7 additions & 1 deletion tests/testthat/test-include-hba1c.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ test_that("casing of input variables doesn't matter", {
})

test_that("verification works for DuckDB Database", {
actual <- arrow::to_duckdb(lab_forsker) |>
skip_on_cran()
skip_if_not_installed("duckplyr")
actual <- duckplyr::as_duckplyr_tibble(lab_forsker) |>
include_hba1c()

actual_rows <- actual |>
Expand All @@ -70,6 +72,8 @@ test_that("verification works for DuckDB Database", {
})

test_that("verification works for Arrow Tables (from Parquet)", {
skip_on_cran()
skip_if_not_installed("arrow")
actual <- arrow::as_arrow_table(lab_forsker) |>
include_hba1c() |>
# TODO: Arrow doesn't like the `row_number()` function, find a fix?
Expand Down Expand Up @@ -97,6 +101,8 @@ test_that("verification works for data.frame", {
})

test_that("verification works for data.table", {
skip_on_cran()
skip_if_not_installed("data.table")
actual <- data.table::as.data.table(lab_forsker) |>
include_hba1c()

Expand Down
Loading

0 comments on commit 25db86d

Please sign in to comment.