Skip to content

Commit

Permalink
lil updates ahead of cran submission
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Mar 15, 2024
1 parent d74c53b commit ff59e3c
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 376 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ pkgdown
# others
^renv$
^renv\.lock$
^cran-comments\.md$
16 changes: 8 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
Package: cardx
Title: Extra Analysis Results Data Utilities
Version: 0.0.0.9042
Version: 0.1.0
Authors@R: c(
person("Daniel", "Sjoberg", , "sjobergd@gene.com", role = c("aut", "cre")),
person("Daniel", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre")),
person("F. Hoffmann-La Roche AG", role = c("cph", "fnd"))
)
Description: Extra Analysis Results Data (ARD) functions. The package
supplements the ARD functions from the 'cards' package, exporting
functions to put statistical results in the ARD format.
Description: Create extra Analysis Results Data (ARD) summary objects.
The package supplements the simple ARD functions from the 'cards'
package, exporting functions to put statistical results in the ARD
format. These objects are used and re-used to construct summary
tables, visualizations, and written reports.
License: Apache License 2.0
URL: https://github.com/insightsengineering/cardx
BugReports: https://github.com/insightsengineering/cardx/issues
Depends:
R (>= 4.1)
Imports:
cards (>= 0.0.0.9049),
cards (>= 0.1.0),
cli (>= 3.6.1),
dplyr (>= 1.1.2),
glue (>= 1.6.2),
Expand All @@ -26,8 +28,6 @@ Suggests:
spelling,
testthat (>= 3.2.0),
withr
Remotes:
insightsengineering/cards
Config/Needs/website: insightsengineering/nesttemplate
Config/testthat/edition: 3
Config/testthat/parallel: true
Expand Down
13 changes: 0 additions & 13 deletions LICENSE

This file was deleted.

5 changes: 2 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# cardx 0.0.0.9042
# cardx 0.1.0

### New Features
* New package!
* Initial release.
3 changes: 2 additions & 1 deletion R/ard_mcnemartest.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ ard_mcnemartest <- function(data, by, variable, ...) {
#' )
#'
#' @keywords internal
#' @noRd
.format_mcnemartest_results <- function(by, variable, lst_tidy, ...) {
# build ARD ------------------------------------------------------------------
ret <-
cards::tidy_as_ard(
lst_tidy = lst_tidy,
tidy_result_names = c("statistic", "p.value", "method"),
fun_args_to_record = c("correct"),
formals = formals(asNamespace("stats")[["mcnemar.test"]]),
# formals = formals(asNamespace("stats")[["mcnemar.test"]]),
passed_args = dots_list(...),
lst_ard_columns = list(group1 = by, variable = variable, context = "mcnemartest")
)
Expand Down
3 changes: 2 additions & 1 deletion R/ard_moodtest.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ ard_moodtest <- function(data, by, variable, ...) {
#' broom::tidy()
#' )
#' )
#' @noRd
.format_moodtest_results <- function(by, variable, lst_tidy, ...) {
# build ARD ------------------------------------------------------------------
ret <-
cards::tidy_as_ard(
lst_tidy = lst_tidy,
tidy_result_names = c("statistic", "p.value", "method", "alternative"),
formals = formals(asNamespace("stats")[["mood.test.default"]]),
# formals = formals(asNamespace("stats")[["mood.test.default"]]),
passed_args = c(dots_list(...)),
lst_ard_columns = list(group1 = by, variable = variable, context = "moodtest")
)
Expand Down
4 changes: 3 additions & 1 deletion R/ard_ttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ ard_paired_ttest <- function(data, by, variable, id, ...) {
#' broom::tidy()
#' )
#' )
#' @noRd
.format_ttest_results <- function(by, variable, lst_tidy, paired, ...) {
# build ARD ------------------------------------------------------------------
ret <-
Expand All @@ -137,7 +138,7 @@ ard_paired_ttest <- function(data, by, variable, id, ...) {
"method", "alternative"
),
fun_args_to_record = c("mu", "paired", "var.equal", "conf.level"),
formals = formals(asNamespace("stats")[["t.test.default"]]),
# formals = formals(asNamespace("stats")[["t.test.default"]]),
passed_args = c(list(paired = paired), dots_list(...)),
lst_ard_columns = list(group1 = by, variable = variable, context = "ttest")
)
Expand Down Expand Up @@ -170,6 +171,7 @@ ard_paired_ttest <- function(data, by, variable, id, ...) {
#' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |>
#' dplyr::arrange(USUBJID, ARM) |>
#' cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID")
#' @noRd
.paired_data_pivot_wider <- function(data, by, variable, id, env = rlang::caller_env()) {
# check the number of levels before pivoting data to wider format
if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) {
Expand Down
38 changes: 2 additions & 36 deletions R/ard_wilcoxtest.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ ard_paired_wilcoxtest <- function(data, by, variable, id, ...) {
#' )
#'
#' @keywords internal
#' @noRd
.format_wilcoxtest_results <- function(by, variable, lst_tidy, paired, ...) {
# build ARD ------------------------------------------------------------------
ret <-
Expand All @@ -144,7 +145,7 @@ ard_paired_wilcoxtest <- function(data, by, variable, id, ...) {
"mu", "paired", "exact", "correct", "conf.int",
"conf.level", "tol.root", "digits.rank"
),
formals = formals(asNamespace("stats")[["wilcox.test.default"]]),
# formals = formals(asNamespace("stats")[["wilcox.test.default"]]),
passed_args = c(list(paired = paired), dots_list(...)),
lst_ard_columns = list(group1 = by, variable = variable, context = "ttest")
)
Expand All @@ -159,41 +160,6 @@ ard_paired_wilcoxtest <- function(data, by, variable, id, ...) {
cards::tidy_ard_column_order()
}


#' Convert long paired data to wide
#'
#'
#' @param data (`data.frame`)\cr a data frame that is one line per subject per group
#' @param by (`string`)\cr by column name
#' @param variable (`string`)\cr variable column name
#' @param id (`string`)\cr subject id column name
#' @param env (`environment`) used for error messaging. Default is `rlang::caller_env()`
#'
#' @return a wide data frame
#' @keywords internal
#' @examples
#' cards::ADSL[c("ARM", "AGE")] |>
#' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
#' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |>
#' dplyr::arrange(USUBJID, ARM) |>
#' cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID")
.paired_data_pivot_wider <- function(data, by, variable, id, env = rlang::caller_env()) {
# check the number of levels before pivoting data to wider format
if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) {
cli::cli_abort("The {.arg by} argument must have two and only two levels.", call = env)
}

data |>
# arrange data so the first group always appears first
dplyr::arrange(.data[[by]]) |>
tidyr::pivot_wider(
id_cols = all_of(id),
names_from = all_of(by),
values_from = all_of(variable)
) |>
stats::setNames(c(id, "by1", "by2"))
}

.df_wilcoxtest_stat_labels <- function() {
dplyr::tribble(
~stat_name, ~stat_label,
Expand Down
2 changes: 2 additions & 0 deletions R/proportion_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ proportion_ci_strat_wilson <- function(x,
#' weights <- rep(1 / length(ns), length(ns))
#'
#' cardx:::.strata_normal_quantile(vars, weights, 0.95)
#' @noRd
.strata_normal_quantile <- function(vars, weights, conf.level) {
summands <- weights^2 * vars
# Stratified quantile
Expand Down Expand Up @@ -377,6 +378,7 @@ proportion_ci_strat_wilson <- function(x,
#' ns <- c(22, 18, 17, 17, 14, 12)
#'
#' cardx:::.update_weights_strat_wilson(vs, sq, ws, ns, 100, 0.95, 0.001)
#' @noRd
.update_weights_strat_wilson <- function(vars,
strata_qnorm,
initial_weights,
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cardx <a href="https://insightsengineering.github.io/cardx"><img src="man/figures/logo.png" align="right" height="138" alt="cardx website" /></a>
# cardx <a href="https://insightsengineering.github.io/cardx/"><img src="man/figures/logo.png" align="right" height="138" alt="cardx website" /></a>

<!-- badges: start -->
[![R-CMD-check](https://github.com/insightsengineering/cardx/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/insightsengineering/cardx/actions/workflows/R-CMD-check.yaml)
Expand All @@ -11,9 +11,16 @@ This is the source repository of the `cardx` R package.

## Installation

The latest development version of `{cardx}` can directly be installed from GitHub by running the following:
Install cards from CRAN with:

```r
if (!require("pak")) install.packages("pak")
pak::pak("insightsengineering/cardx")
``` r
install.packages("cardx")
```

You can install the development version of cards from
[GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("insightsengineering/cardx")
```
17 changes: 17 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Test environments
* Ubuntu 18.04 LTS (on github actions), devel, release, oldrel-1, oldrel-2, oldrel-3, oldrel-4
* Windows Server 2019 (on github actions), release
* macOS (on github actions), release
* win-builder devel

## R CMD check results

0 errors | 0 warnings | 1 note

Maintainer: ‘Daniel D. Sjoberg <[email protected]>’

New submission

## Additional Comments

* Thank you for your time!
4 changes: 2 additions & 2 deletions man/cardx-package.Rd

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

38 changes: 0 additions & 38 deletions man/dot-format_mcnemartest_results.Rd

This file was deleted.

37 changes: 0 additions & 37 deletions man/dot-format_moodtest_results.Rd

This file was deleted.

41 changes: 0 additions & 41 deletions man/dot-format_ttest_results.Rd

This file was deleted.

Loading

0 comments on commit ff59e3c

Please sign in to comment.