Skip to content

Commit

Permalink
Ensure jackknife function returns a tbl_svy when it should.
Browse files Browse the repository at this point in the history
  • Loading branch information
bschneidr committed Oct 10, 2023
1 parent 250fe36 commit bd2dd28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/as_jackknife_design.R
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ as_random_group_jackknife_design.survey.design <- function(
jk_design$variables[[group_var_name]] <- design_vars[['RANDOM_GROUP_VAR_UNIT']]
}

if (inherits(design, 'tbl_svy') && ('package:srvyr' %in% search())) {
jk_design <- srvyr::as_survey_rep(
jk_design
)
}

# Return the result
jk_design$call <- sys.call(which = -1)
return(jk_design)
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-random-group-jackknife.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,20 @@ set.seed(2014)
)
}, regexp = "Overwriting.+stype")
})

# Works for more specialized classes of survey designs ----

test_that(
desc = "Returns `tbl_svy` if the input is a `tbl_svy` and 'srvyr' is loaded", {
library(srvyr)
expect_true(
suppressMessages({
dstrat_nofpc |> as_survey() |>
as_random_group_jackknife_design(
replicates = 10
) |>
inherits('tbl_svy')
})
)
}
)

0 comments on commit bd2dd28

Please sign in to comment.