Skip to content

Commit

Permalink
accomplish all tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz2101 committed May 21, 2024
1 parent f504bef commit 3ca1b74
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Suggests:
broom.helpers (>= 1.15.0),
broom.mixed (>= 0.2.9),
car (>= 3.0-11),
effectsize (>= 0.6.0),
effectsize (>= 0.8.8),
emmeans (>= 1.7.3),
geepack (>= 1.3.2),
ggsurvfit (>= 1.0.0),
Expand Down
28 changes: 9 additions & 19 deletions R/ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#' The data are then passed as
#' `effectsize::hedges_g(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...)`.
#'
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx"))
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters"), reference_pkg = "cardx"))
#' cards::ADSL |>
#' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
#' ard_effectsize_hedges_g(by = ARM, variables = AGE)
Expand All @@ -52,7 +52,7 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...)
set_cli_abort_call()

# check installed packages ---------------------------------------------------
check_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")
check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")

# check/process inputs -------------------------------------------------------
check_not_missing(data)
Expand All @@ -77,19 +77,12 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...)
variable = variable,
lst_tidy =
cards::eval_capture_conditions(
# Need to eval in NAMESAPCE DUE TO BUG IN effectsize v0.8.7.
# Can remove this later along with requirements for withr to be installed.
# Will also need to remove `hedges_g` from globalVariables()
withr::with_namespace(
package = "effectsize",
code =
hedges_g(
reformulate2(by, response = variable),
data = data |> tidyr::drop_na(all_of(c(by, variable))),
paired = FALSE,
ci = conf.level,
...
)
effectsize::hedges_g(
reformulate2(by, response = variable),
data = data |> tidyr::drop_na(all_of(c(by, variable))),
paired = FALSE,
ci = conf.level,
...
) |>
parameters::standardize_names(style = "broom") |>
dplyr::mutate(method = "Hedge's G")
Expand Down Expand Up @@ -143,10 +136,7 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level =
.paired_data_pivot_wider(by = by, variable = variable, id = id) |>
tidyr::drop_na(any_of(c("by1", "by2")))
# perform paired cohen's d test
withr::with_namespace(
package = "effectsize",
code = hedges_g(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...)
) |>
effectsize::hedges_g(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...) |>
parameters::standardize_names(style = "broom") |>
dplyr::mutate(method = "Paired Hedge's G")
}),
Expand Down
2 changes: 1 addition & 1 deletion R/cardx-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
## usethis namespace: end
NULL

utils::globalVariables(c(".", "hedges_g"))
utils::globalVariables(c("."))
2 changes: 1 addition & 1 deletion man/ard_effectsize_hedges_g.Rd

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

6 changes: 1 addition & 5 deletions tests/testthat/test-ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
skip_if_not(is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx"))
skip_if_not(is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx"))

test_that("ard_effectsize_hedges_g() works", {
withr::local_namespace("effectsize")

expect_error(
ard_hedges_g <-
cards::ADSL |>
Expand Down Expand Up @@ -45,8 +43,6 @@ test_that("ard_effectsize_hedges_g() works", {
})

test_that("ard_effectsize_paired_hedges_g() works", {
withr::local_namespace("effectsize")

ADSL_paired <-
cards::ADSL[c("ARM", "AGE")] |>
dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
Expand Down

0 comments on commit 3ca1b74

Please sign in to comment.