Skip to content

Commit

Permalink
Merge pull request #8 from nanxstats/setup
Browse files Browse the repository at this point in the history
Basic setup and style
  • Loading branch information
wangben718 authored Apr 12, 2024
2 parents 896fb29 + 271688d commit 07c7034
Show file tree
Hide file tree
Showing 27 changed files with 292 additions and 131 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 3 additions & 5 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
^.*\.Rproj$
^\.Rproj\.user$
^data-raw$

^_pkgdown\.yml$
^pkgdown$
^docs$
^LICENSE$
^LICENSES_THIRD_PARTY$
^LICENSE\.md$
^LICENSE_THIRD_PARTY\.md$
^\.github$
^codecov\.yml$
^README\.Rmd$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.rtf linguist-generated
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

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

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

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

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

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
.RData
.Ruserdata

.DS_Store
docs/
docs
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: metalite.sl
Title: Subject-level Analysis Using 'metalite'
Version: 0.1.0
Authors@R:c(
Authors@R: c(
person("Benjamin", "Wang", email = "[email protected]", role = c("aut", "cre")),
person("Yujie", "Zhao", role = "aut"),
person("Hiroaki", "Fukuda", role = "aut"),
Expand All @@ -12,19 +12,19 @@ Description: Provide subject-level analysis.
Depends: R (>= 4.1.0)
License: GPL (>= 3)
Imports:
r2rtf,
glue,
metalite,
metalite.ae,
r2rtf,
reactable,
glue,
stringr
Suggests:
dplyr,
knitr,
testthat (>= 3.0.0),
tidyr,
knitr
Encoding: UTF-8
tidyr
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/testthat/edition: 3
22 changes: 11 additions & 11 deletions R/collect.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
#'
#' @examples
#' meta <- meta_sl_example()
#' meta |>
#' collect_baseline(
#' population = "apat",
#' parameter = "age"
#' )
collect_baseline <- function(meta,
population,
parameter,
type = "Subjects",
use_na = c("ifany", "no", "always"),
display_total = TRUE) {
#' meta |> collect_baseline(
#' population = "apat",
#' parameter = "age"
#' )
collect_baseline <- function(
meta,
population,
parameter,
type = "Subjects",
use_na = c("ifany", "no", "always"),
display_total = TRUE) {
use_na <- match.arg(use_na)

title <- c(
Expand Down
19 changes: 11 additions & 8 deletions R/format_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#' Prepare data for baseline characteristic table
#'
#' @param outdata A metadata object created by [prepare_base_char()].
#' @param display_col Column wants to display on the table. Term could be selected from `c("n", "prop", "total")`.
#' @param display_col Column wants to display on the table.
#' The term could be selected from `c("n", "prop", "total")`.
#' @param digits_prop Number of digits for proportion columns.
#' @param display_stat A vector of statistics term name.
#' The term name could be selected from c("mean", "sd", "se", "median", "q1 to q3", "range", "q1", "q3", "min", "max").
#' The term name could be selected from
#' `c("mean", "sd", "se", "median", "q1 to q3", "range", "q1", "q3", "min", "max")`.
#'
#' @return A list of analysis raw datasets.
#'
Expand All @@ -34,10 +36,11 @@
#' meta |>
#' prepare_base_char(parameter = "age;gender") |>
#' format_base_char()
format_base_char <- function(outdata,
display_col = c("n", "prop", "total"),
digits_prop = 1,
display_stat = c("mean", "sd", "se", "median", "q1 to q3", "range")) {
format_base_char <- function(
outdata,
display_col = c("n", "prop", "total"),
digits_prop = 1,
display_stat = c("mean", "sd", "se", "median", "q1 to q3", "range")) {
n_group <- length(outdata$group_label)

# Select statistics want to display
Expand All @@ -56,7 +59,7 @@ format_base_char <- function(outdata,
}
}

# create output
# Create output
tbl <- list()

if ("n" %in% display_col) {
Expand Down Expand Up @@ -109,10 +112,10 @@ format_base_char <- function(outdata,
(1 + n_group + ifelse("total" %in% display_col, 1, 0) + 1)
)]


rownames(within_tbl) <- NULL
outdata$tbl <- within_tbl
outdata$display_col <- display_col
outdata$display_stat <- display_stat

return(outdata)
}
21 changes: 10 additions & 11 deletions R/prepare_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
#'
#' @examples
#' meta <- meta_sl_example()
#'
#' meta |>
#' prepare_base_char()
prepare_base_char <- function(meta,
population = "apat",
observation = "wk12",
analysis = "base_char",
parameter = paste(names(meta$parameter), collapse = ";")) {
#' meta |> prepare_base_char()
prepare_base_char <- function(
meta,
population = "apat",
observation = "wk12",
analysis = "base_char",
parameter = paste(names(meta$parameter), collapse = ";")) {
parameters <- unlist(strsplit(parameter, ";"))

# obtain variables
Expand Down Expand Up @@ -77,18 +76,18 @@ prepare_base_char <- function(meta,
n_pop <- n_pop[, c(length(group) + 2, 1:(length(group) + 1))]
n_pop$var_label <- "-----"

# get the baseline characteristics variables in adsl
# Get the baseline characteristics variables in adsl
# char_var <- collect_adam_mapping(meta, analysis)$var_name
char_var <- do.call(c, lapply(parameters, function(x) {
metalite::collect_adam_mapping(meta, x)$var
}))

# get the baseline characteristics counts
# Get the baseline characteristics counts
char_n <- lapply(parameters, function(x) {
collect_baseline(meta, population, x)[[2]]
})

# get the baseline characteristics propositions
# Get the baseline characteristics propositions
char_prop <- lapply(parameters, function(x) {
collect_baseline(meta, population, x)[[3]]
})
Expand Down
37 changes: 22 additions & 15 deletions R/react_base_char.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@

#' Display interactive baseline characteristic tables with AE subgroup analysis
#'
#' @param metadata_sl A metadata created by [metalite], which builds the baseline characteristic table
#' @param metadata_ae A metadata created by [metalite], which builds the AE subgroup specific table
#' @param metadata_sl A metadata created by [metalite],
#' which builds the baseline characteristic table
#' @param metadata_ae A metadata created by [metalite],
#' which builds the AE subgroup specific table
#' @param population A character value of population term name.
#' The term name is used as key to link information.
#' @param observation A character value of observation term name.
#' The term name is used as key to link information.
#' @param display_total Display total column or not.
#' @param sl_parameter A character value of parameter term name for the baseline characteristic table.
#' @param sl_parameter A character value of parameter term name for
#' the baseline characteristic table.
#' The term name is used as key to link information.
#' @param ae_subgroup A vector of strubf to specify the subgroups in the AE subgroup specific table
#' @param ae_specific A string specifying the AE specific category
#' @param ae_subgroup A vector of strubf to specify the subgroups
#' in the AE subgroup specific table.
#' @param ae_specific A string specifying the AE specific category.
#' @param width A numeric value of width of the table in pixels.
#'
#' @return An reactable combing both baseline characteristic table and AE subgroup specific tables
#' @return An reactable combing both baseline characteristic table
#' and AE subgroup specific tables.
#'
#' @export
#'
#' @examples
Expand All @@ -48,15 +54,16 @@
#' width = 1200
#' )
#' }
react_base_char <- function(metadata_sl,
metadata_ae,
population = "apat",
observation = "wk12",
display_total = TRUE,
sl_parameter = "age;gender;race",
ae_subgroup = c("gender", "race"),
ae_specific = "rel",
width = 1200) {
react_base_char <- function(
metadata_sl,
metadata_ae,
population = "apat",
observation = "wk12",
display_total = TRUE,
sl_parameter = "age;gender;race",
ae_subgroup = c("gender", "race"),
ae_specific = "rel",
width = 1200) {
# ----------------------------------------- #
# total setting #
# ----------------------------------------- #
Expand Down
19 changes: 10 additions & 9 deletions R/react_subgroup_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

#' Create interactive table for a subgroup
#'
#' @param tbl Tibble to create reactable
#' @param group Treatment group label
#' @param subgroup_name Subgroup label
#' @param tbl A tibble to create reactable.
#' @param group Treatment group label.
#' @param subgroup_name Subgroup label.
#'
#' @return A reactable combing both baseline characteristic table
#' and AE subgroup specific tables for a subgroup
react_subgroup_table <- function(tbl,
group,
subgroup_name) {
#' @return A reactable combining both baseline characteristic table
#' and AE subgroup specific tables for a subgroup.
react_subgroup_table <- function(
tbl,
group,
subgroup_name) {
names(tbl) <- tolower(names(tbl))
subgroup_name <- tolower(subgroup_name)
race_columns <- grep(tolower(subgroup_name), tolower(names(tbl)), value = TRUE)
Expand Down Expand Up @@ -80,7 +81,7 @@ react_subgroup_table <- function(tbl,
)
}

# Borrow from metalite.ae
# Borrowed from metalite.ae
#' Format AE specific analysis
#'
#' @inheritParams metalite.ae::format_ae_specific
Expand Down
Loading

0 comments on commit 07c7034

Please sign in to comment.