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 github action to knit Rmd #2

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a8fb75e
Add github action to knit Rmd
stefpiatek Dec 23, 2024
ce8e2b4
Update Rmd to test out action
stefpiatek Dec 23, 2024
0814e92
Add Pandoc
stefpiatek Dec 23, 2024
e2bcc5a
Use r-lib actions for pandoc install
stefpiatek Dec 23, 2024
333ed9a
Use r-lib actions for pandoc install
stefpiatek Dec 23, 2024
8006799
Try installing omopcept in deps
stefpiatek Dec 23, 2024
4fd4ea3
Add renv
stefpiatek Dec 23, 2024
fd3fb00
Add renv
stefpiatek Dec 23, 2024
f4c55d2
Add omopcept
stefpiatek Dec 23, 2024
3c5fcc5
Add token to read omopcept
stefpiatek Dec 23, 2024
e7ce62b
Hopefully add omopcept and commit
stefpiatek Dec 23, 2024
5b48afb
This is getting silly now
stefpiatek Dec 23, 2024
ab4faac
Only pull current branch
stefpiatek Dec 23, 2024
10ca4ea
Try and push changes now
stefpiatek Dec 23, 2024
f2fbef6
Add omopcept
github-actions[bot] Dec 23, 2024
7ef7656
Remove extra install of omopcept
stefpiatek Dec 23, 2024
d408024
Remove installing of omopcept on its own
stefpiatek Dec 23, 2024
3336e8f
Update omopcept
stefpiatek Jan 13, 2025
74a18db
Add project id
stefpiatek Jan 13, 2025
7e6e194
try to fix Error in `fortify()`:! `data` must be a <data.frame>
Jan 13, 2025
55dfc8e
Convert dynamic docs to markdown
stefpiatek Jan 13, 2025
fdd40f6
Merge branch 'stefpiatek/knit-rmd-action' of github.com:SAFEHR-data/s…
stefpiatek Jan 13, 2025
4e6e8f8
Knit files in the right place
stefpiatek Jan 13, 2025
b9a4d99
Knit Rmd files
github-actions[bot] Jan 13, 2025
33aab1e
Update instructions for knitting
stefpiatek Jan 13, 2025
22b42e5
Knit Rmd files
github-actions[bot] Jan 13, 2025
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
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
55 changes: 55 additions & 0 deletions .github/workflows/knit-rmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Knit Rmd Files

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
knit:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Setup pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Checkout repository
uses: actions/checkout@v4
# Only pull current branch, not the merge outcome so that we can commit the output
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 0

- name: Set up R
uses: r-lib/actions/setup-r@v2

- name: Setup Renv
uses: r-lib/actions/setup-renv@v2
env:
GITHUB_PAT: ${{ secrets.READ_OMOPCEPT_PAT }}

- name: Find and knit Rmd files
run: |
Rscript -e '
rmd_files <- list.files(path = "dynamic-docs", pattern = "\\.Rmd$", recursive = TRUE, full.names = TRUE)
for (file in rmd_files) {
rmarkdown::render(file, output_format = "md_document", output_dir = ".")
}
'

- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Knit Rmd files" || echo "No changes to commit"

- name: Push changes
uses: ad-m/[email protected]
with:
branch: ${{ github.head_ref || github.ref_name }}
787 changes: 386 additions & 401 deletions 02-omop-walkthrough-critical-care.md

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ author: Andy South
date: "2024-12-03"
---

<!-- *.md is generated from `*.Rmd` in /dynamic-docs/, to update edit `*.Rmd`, re-knit, copy `*.md` & the `*_files` folder to root, delete YAML header so it displays better in Github, don't delete `.html` because that will delete folder and images used by the md. We can automate this process later. -->
<!--
*.md is generated from `*.Rmd` in /dynamic-docs/, this is updated in a github action,
you can regenerate this by running the "Find and knit Rmd files" step from the github action.
-->


This document is an introductory walkthrough, demonstrating how to read into R some OMOP data from a series of csv files, join on concept names and explore and visualise the data.
Expand All @@ -19,6 +22,10 @@ knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```

## Installing & loading required packages

If any of the `library($PACKAGE)` packages aren't installed, you can install them by running `install.packages("$PACKAGE")`,
replacing `$PACKAGE` with the package name.

```{r packages}

# install omopcept from Github if not installed
Expand Down Expand Up @@ -55,10 +62,10 @@ if (! file.exists(file.path(destdata,"person.csv")))
{
# Make GitHub API request to list contents of given path
response <- gh::gh(glue::glue("/repos/{repo}/contents/{path}"))

# Download all files to the destination dir
purrr::walk(response, ~ download.file(.x$download_url, destfile = file.path(destdata, .x$name)))

list.files(destdata)
}

Expand Down Expand Up @@ -119,7 +126,7 @@ omop_named <- omop |> omop_join_name_all()
names(omop_named$person) |> str_subset("name")

# now the gender name column can be used in the plot
ggplot(omop_named$person, aes(x=year_of_birth, fill = as.factor(gender_concept_name))) +
ggplot(omop_named$person, aes(x=year_of_birth, fill=as.factor(gender_concept_name))) +
geom_bar() +
theme_minimal()

Expand Down Expand Up @@ -199,7 +206,12 @@ joined_mp <- omop_named$measurement |>

freq_top_measures <- joined_mp |>
count(measurement_concept_name,gender_concept_name, sort=TRUE) |>
filter(n > 1)
filter(n > 1) |>
#TODO not sure why collect() needed here
#but without it the following ggplot erros with
#Error in `fortify()`:! `data` must be a <data.frame>, or an object coercible by
#something to do with arrow tables ?
collect()

#plot
freq_top_measures |>
Expand Down
Loading