Skip to content

Commit caa91b4

Browse files
authored
Merge pull request #6 from CHOP-CGTInformatics/codex/pkgdown-site
Add pkgdown site and mock data
2 parents 8e610d3 + 1b9e1c8 commit caa91b4

22 files changed

Lines changed: 770 additions & 85 deletions

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
^\.\.Rcheck$
66
^LICENSE\.md$
77
^README\.Rmd$
8+
^AGENTS\.md$
89
^\.github$
910
^_pkgdown\.yml$
1011
^docs$

DESCRIPTION

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ Depends:
99
Description: Provides tools to explore REDCap projects, summarize project
1010
structure, and flag common data quality issues for data managers.
1111
License: What license is it under?
12+
URL: https://chop-cgtinformatics.github.io/REDCapExploreR/,
13+
https://github.com/CHOP-CGTInformatics/REDCapExploreR
14+
BugReports: https://github.com/CHOP-CGTInformatics/REDCapExploreR/issues
1215
Encoding: UTF-8
16+
LazyData: true
1317
Imports:
1418
cli,
1519
DT,
@@ -25,7 +29,10 @@ Imports:
2529
tidyr,
2630
tidyselect
2731
Suggests:
32+
knitr,
33+
rmarkdown,
2834
testthat (>= 3.0.0)
2935
Config/testthat/edition: 3
3036
Roxygen: list(markdown = TRUE)
3137
RoxygenNote: 7.3.3
38+
VignetteBuilder: knitr

R/codebook.R

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ build_codebook <- function(redcap_uri, token) {
4444
)
4545
)
4646

47+
get_codebook(project)
48+
}
49+
50+
get_codebook <- function(project) {
4751
codebook <- list(
4852
fields = get_codebook_fields(project),
4953
choices = get_codebook_choices(project),
@@ -260,8 +264,11 @@ get_codebook_fields <- function(project) {
260264
.data$event_count,
261265
.data$event_names,
262266
.data$repeating_status,
263-
field_note = if ("field_note" %in% names(metadata))
264-
as.character(.data$field_note) else NA_character_,
267+
field_note = if ("field_note" %in% names(metadata)) {
268+
as.character(.data$field_note)
269+
} else {
270+
NA_character_
271+
},
265272
matrix_group_name = if ("matrix_group_name" %in% names(metadata)) {
266273
as.character(.data$matrix_group_name)
267274
} else {
@@ -591,10 +598,16 @@ get_codebook_validation_label <- function(
591598
map_chr(seq_along(validation_type), \(index) {
592599
pieces <- c(
593600
validation_type[[index]],
594-
if (!get_is_missing(validation_min[[index]]))
595-
paste("min", validation_min[[index]]) else NA_character_,
596-
if (!get_is_missing(validation_max[[index]]))
597-
paste("max", validation_max[[index]]) else NA_character_
601+
if (!get_is_missing(validation_min[[index]])) {
602+
paste("min", validation_min[[index]])
603+
} else {
604+
NA_character_
605+
},
606+
if (!get_is_missing(validation_max[[index]])) {
607+
paste("max", validation_max[[index]])
608+
} else {
609+
NA_character_
610+
}
598611
)
599612
pieces <- pieces[!get_is_missing(pieces)]
600613

R/data.R

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#' @title Mock REDCap project
2+
#'
3+
#' @description
4+
#' A fully synthetic REDCap-shaped project list used in package examples,
5+
#' vignettes, and tests. The project is longitudinal and includes
6+
#' demographics, follow-up, checkbox, validation, completion status, and
7+
#' repeating instrument fields.
8+
#'
9+
#' @format A list with REDCap API-like data frames:
10+
#' \describe{
11+
#' \item{data}{Synthetic REDCap records.}
12+
#' \item{metadata}{Synthetic REDCap data dictionary metadata.}
13+
#' \item{events}{Synthetic longitudinal event metadata.}
14+
#' \item{event_instruments}{Synthetic event-instrument mapping.}
15+
#' \item{instruments}{Synthetic instrument labels.}
16+
#' \item{repeating_instruments}{Synthetic repeating instrument settings.}
17+
#' \item{project_info}{Synthetic project-level metadata.}
18+
#' }
19+
#' @source Generated by `data-raw/mock-data.R`.
20+
"mock_redcap_project"
21+
22+
#' @title Mock Record Status Dashboard data
23+
#'
24+
#' @description
25+
#' A synthetic dashboard tile table generated from `mock_redcap_project` with
26+
#' REDCapExploreR's internal record-status logic. This dataset is suitable for
27+
#' examples of [plot_record_status()].
28+
#'
29+
#' @format A tibble with one row per record, event, and form tile.
30+
#' @source Generated by `data-raw/mock-data.R`.
31+
"mock_record_status_data"
32+
33+
#' @title Mock REDCap codebook
34+
#'
35+
#' @description
36+
#' A synthetic `redcap_codebook` object generated from `mock_redcap_project`
37+
#' with REDCapExploreR's internal codebook logic.
38+
#'
39+
#' @format A `redcap_codebook` list with `fields`, `choices`, `forms`, `events`,
40+
#' `event_instruments`, `repeating`, and `project` elements.
41+
#' @source Generated by `data-raw/mock-data.R`.
42+
"mock_codebook"
43+
44+
#' @title Mock REDCap quality report
45+
#'
46+
#' @description
47+
#' A synthetic `redcap_quality_report` object generated from
48+
#' `mock_redcap_project` with REDCapExploreR's internal quality-report logic.
49+
#'
50+
#' @format A `redcap_quality_report` list with `findings`, `summaries`, and
51+
#' `metadata` elements.
52+
#' @source Generated by `data-raw/mock-data.R`.
53+
"mock_quality_report"

R/plot_record_status.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#' @returns A ggplot object.
4747
#'
4848
#' @examples
49+
#' plot_record_status(mock_record_status_data)
50+
#'
51+
#' plot_record_status(mock_record_status_data, mode = "compact")
52+
#'
4953
#' \dontrun{
5054
#' data <- get_record_status_data(
5155
#' redcap_uri = Sys.getenv("REDCAP_URI"),

R/quality_report.R

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ build_quality_report <- function(
112112
redcap_uri = redcap_uri,
113113
token = token
114114
)
115+
116+
get_quality_report(
117+
project = project,
118+
checks = checks,
119+
sparse_threshold = sparse_threshold,
120+
outlier_iqr_multiplier = outlier_iqr_multiplier,
121+
progress_bar = progress_bar,
122+
progress_enabled = progress_enabled,
123+
progress_force = progress_force
124+
)
125+
}
126+
127+
get_quality_report <- function(
128+
project,
129+
checks,
130+
sparse_threshold,
131+
outlier_iqr_multiplier,
132+
progress_bar = NULL,
133+
progress_enabled = FALSE,
134+
progress_force = FALSE
135+
) {
115136
update_report_progress(
116137
progress_bar,
117138
progress_enabled,
@@ -360,11 +381,14 @@ close_report_progress <- function(progress_bar, enabled) {
360381
}
361382

362383
get_quality_project <- function(redcap_uri, token) {
363-
out <- get_api_project(pull_redcap_project(
384+
get_quality_project_data(pull_redcap_project(
364385
redcap_uri = redcap_uri,
365386
token = token
366387
))
388+
}
367389

390+
get_quality_project_data <- function(project) {
391+
out <- get_api_project(project)
368392
out$record_id_field <- get_record_id_field_report(out$data, out$metadata)
369393
out
370394
}

README.Rmd

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ knitr::opts_chunk$set(
1919
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
2020
<!-- badges: end -->
2121

22-
The goal of REDCapExploreR is to provide users with tools to post-process and perform exploratory data analysis on REDCap project data through the REDCap API.
22+
The goal of REDCapExploreR is to provide users with tools to perform exploratory data analysis on and quality assessments of REDCap project data using the REDCap API.
2323

2424
This repository is in early stages active development!
2525

@@ -30,40 +30,3 @@ You can install the development version of REDCapExploreR like so:
3030
``` r
3131
devtools::install_github("CHOP-CGTInformatics/REDCapExploreR")
3232
```
33-
34-
## Example
35-
36-
This is a basic example which shows you how to solve a common problem:
37-
38-
```{r example}
39-
library(REDCapExploreR)
40-
## basic example code
41-
```
42-
43-
### Recreating a Project's Record Status Dashboard
44-
45-
```{r, eval=FALSE}
46-
redcap_uri <- Sys.getenv("REDCAP_URI")
47-
token <- Sys.getenv("REDCAP_TOKEN")
48-
49-
data <- get_record_status_data(redcap_uri = redcap_uri, token = token)
50-
51-
plot_record_status(data)
52-
```
53-
54-
For larger projects, use compact mode to reduce x-axis text size, truncate long
55-
form labels, and draw lighter tile borders.
56-
57-
```{r, eval=FALSE}
58-
plot_record_status(data, mode = "compact")
59-
60-
plot_record_status(data, mode = "compact", form_label_max = 20)
61-
```
62-
63-
Because `plot_record_status()` returns a ggplot object, you can add standard
64-
ggplot2 layers to customize the display.
65-
66-
```{r, eval=FALSE}
67-
plot_record_status(data) +
68-
ggplot2::labs(title = "REDCap Record Status")
69-
```

README.md

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
1010
<!-- badges: end -->
1111

12-
The goal of REDCapExploreR is to provide users with tools to
13-
post-process and perform exploratory data analysis on REDCap project
14-
data through the REDCap API.
12+
The goal of REDCapExploreR is to provide users with tools to perform
13+
exploratory data analysis on and quality assessments of REDCap project
14+
data using the REDCap API.
1515

1616
This repository is in early stages active development!
1717

@@ -22,40 +22,3 @@ You can install the development version of REDCapExploreR like so:
2222
``` r
2323
devtools::install_github("CHOP-CGTInformatics/REDCapExploreR")
2424
```
25-
26-
## Example
27-
28-
This is a basic example which shows you how to solve a common problem:
29-
30-
``` r
31-
library(REDCapExploreR)
32-
## basic example code
33-
```
34-
35-
### Recreating a Project’s Record Status Dashboard
36-
37-
``` r
38-
redcap_uri <- Sys.getenv("REDCAP_URI")
39-
token <- Sys.getenv("REDCAP_TOKEN")
40-
41-
data <- get_record_status_data(redcap_uri = redcap_uri, token = token)
42-
43-
plot_record_status(data)
44-
```
45-
46-
For larger projects, use compact mode to reduce x-axis text size, truncate long
47-
form labels, and draw lighter tile borders.
48-
49-
``` r
50-
plot_record_status(data, mode = "compact")
51-
52-
plot_record_status(data, mode = "compact", form_label_max = 20)
53-
```
54-
55-
Because `plot_record_status()` returns a ggplot object, you can add standard
56-
ggplot2 layers to customize the display.
57-
58-
``` r
59-
plot_record_status(data) +
60-
ggplot2::labs(title = "REDCap Record Status")
61-
```

_pkgdown.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
url: https://chop-cgtinformatics.github.io/REDCapExploreR/
2+
3+
home:
4+
title: Exploratory Data Quality Tools for REDCap Projects
5+
6+
template:
7+
bootstrap: 5
8+
bslib:
9+
code_font: {google: "Fira Code"}
10+
primary: "#b22228"
11+
text-muted: "#FFFFFF"
12+
13+
navbar:
14+
bg: primary
15+
structure:
16+
left: [intro, reference]
17+
right: [search, github]
18+
left:
19+
- icon: fa-home
20+
href: index.html
21+
aria-label: Home
22+
- text: Get Started
23+
href: articles/REDCapExploreR.html
24+
- text: Reference
25+
href: reference/index.html
26+
27+
search:
28+
exclude: ['news/index.html', 'AGENTS.html']
29+
30+
reference:
31+
- title: "Pull REDCap Data"
32+
desc: >
33+
Retrieve REDCap project data and metadata from the API.
34+
contents:
35+
- pull_redcap_project
36+
- title: "Build Codebooks"
37+
desc: >
38+
Build and view REDCap project codebooks.
39+
contents:
40+
- build_codebook
41+
- view_codebook
42+
- title: "Build Quality Reports"
43+
desc: >
44+
Build exploratory REDCap data quality reports.
45+
contents:
46+
- build_quality_report
47+
- title: "Record Status Dashboard"
48+
desc: >
49+
Recreate and plot REDCap Record Status Dashboard data.
50+
contents:
51+
- get_record_status_data
52+
- plot_record_status
53+
- title: "Data"
54+
desc: >
55+
Synthetic REDCap-shaped datasets for examples and documentation.
56+
contents:
57+
- mock_redcap_project
58+
- mock_record_status_data
59+
- mock_codebook
60+
- mock_quality_report

0 commit comments

Comments
 (0)