Skip to content

Commit 33ba280

Browse files
Merge pull request #47 from r-causal/attach_propensity
add propensity to imports and handle importing namespace
2 parents 3de7f1e + ea1d7ca commit 33ba280

File tree

12 files changed

+23
-43
lines changed

12 files changed

+23
-43
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Imports:
2020
dplyr,
2121
ggplot2,
2222
gtsummary (>= 2.1.0),
23+
propensity (>= 0.0.0.9000),
2324
purrr,
2425
rlang,
2526
smd,
@@ -43,4 +44,5 @@ LazyData: true
4344
Roxygen: list(markdown = TRUE)
4445
RoxygenNote: 7.3.2
4546
Remotes:
46-
r-causal/tidysmd
47+
r-causal/tidysmd,
48+
r-causal/propensity

R/geom_qq2.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,8 @@
5353
#' geom_abline(intercept = 0, slope = 1, linetype = "dashed")
5454
#'
5555
#' # Compare multiple weights using long format
56-
#' # TODO: Remove vec_data() workaround once propensity implements vctrs methods
57-
#' # Extract numeric data from psw objects first
58-
#' nhefs_for_pivot <- nhefs_weights
59-
#' nhefs_for_pivot$w_ate <- vctrs::vec_data(nhefs_weights$w_ate)
60-
#' nhefs_for_pivot$w_att <- vctrs::vec_data(nhefs_weights$w_att)
6156
#' long_data <- tidyr::pivot_longer(
62-
#' nhefs_for_pivot,
57+
#' nhefs_weights,
6358
#' cols = c(w_ate, w_att),
6459
#' names_to = "weight_type",
6560
#' values_to = "weight"

R/geom_roc.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@
2424
#' geom_abline(intercept = 0, slope = 1, linetype = "dashed")
2525
#'
2626
#' # With grouping by weight
27-
#' # TODO: Remove vec_data() workaround once propensity implements vctrs methods
28-
#' # Extract numeric data from psw objects first
29-
#' nhefs_for_pivot <- nhefs_weights
30-
#' nhefs_for_pivot$w_ate <- vctrs::vec_data(nhefs_weights$w_ate)
31-
#' nhefs_for_pivot$w_att <- vctrs::vec_data(nhefs_weights$w_att)
3227
#' long_data <- tidyr::pivot_longer(
33-
#' nhefs_for_pivot,
28+
#' nhefs_weights,
3429
#' cols = c(w_ate, w_att),
3530
#' names_to = "weight_type",
3631
#' values_to = "weight"

R/utils-validation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ validate_weights <- function(weights, n, arg_name = "weights", call = rlang::cal
1717
if (is.null(weights)) return(invisible(weights))
1818

1919
# Accept both numeric vectors and psw objects from propensity package
20-
is_valid_weights <- is.numeric(weights) || inherits(weights, "psw")
20+
is_valid_weights <- is.numeric(weights) || propensity::is_psw(weights)
2121

2222
if (!is_valid_weights) {
2323
abort(

R/zzz.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.onLoad <- function(libname, pkgname) {
2+
# Ensure propensity's namespace is loaded so its S3 methods are registered
3+
# This is needed for psw objects in nhefs_weights to work properly without
4+
# users having to explicitly load propensity
5+
loadNamespace("propensity")
6+
7+
invisible()
8+
}

man/geom_qq2.Rd

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/geom_roc.Rd

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/Rplots.pdf

0 Bytes
Binary file not shown.

tests/testthat/test-compute_balance.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,8 @@ test_that("balance functions work seamlessly with psw objects from propensity pa
15061506
data(nhefs_weights)
15071507

15081508
# Verify we have psw objects in the dataset
1509-
expect_true(inherits(nhefs_weights$w_cat_ate, "psw"))
1510-
expect_true(inherits(nhefs_weights$w_cat_att_none, "psw"))
1509+
expect_true(propensity::is_psw(nhefs_weights$w_cat_ate))
1510+
expect_true(propensity::is_psw(nhefs_weights$w_cat_att_none))
15111511

15121512
# Test that balance functions work directly with psw weights
15131513
result_smd <- bal_smd(

tests/testthat/test-extract_weight_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test_that("extract_weight_data extracts data from psw objects", {
3636
expect_type(result, "double")
3737

3838
# Should not have psw class anymore
39-
expect_false(inherits(result, "psw"))
39+
expect_false(propensity::is_psw(result))
4040
})
4141

4242
test_that("extract_weight_data preserves values from different psw estimands", {

0 commit comments

Comments
 (0)