Skip to content

Commit

Permalink
tbl_df fix
Browse files Browse the repository at this point in the history
  • Loading branch information
astra-cdc committed Jul 18, 2024
1 parent 6336c17 commit afe38a3
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions R/set_survey.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ set_survey = function(design, opts = "NCHS"
, " (survey.design or svyrep.design) or a data.frame for an unweighted survey."
, " Is: ", class(design)[1] ))

# get rid of non-`data.frame` classes (like tbl_df, tbl), which cause problems for some reason
assert_that(is.data.frame(design$variables))
design$variables %<>% as.data.frame()

if(inherits(design, "svyrep.design") && !isTRUE(attr(design, "prob_set"))) {
assert_that(!("prob" %in% names(design))
, msg = "prob already exists")
Expand Down
2 changes: 1 addition & 1 deletion R/z_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' `namcs2019sv_df` is a data frame.
#'
#' `namcs2019sv` is a survey object created from `namcs2019sv_df`
#' using `[survey::svydesign()]`.
#' using `survey::svydesign()`.
#'
#' @source
#' * SAS data: <https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NAMCS/sas/namcs2019_sas.zip>
Expand Down
8 changes: 5 additions & 3 deletions docs/articles/Advanced-topics.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ articles:
Example-National-Ambulatory-Medical-Care-Survey-NAMCS-tables: Example-National-Ambulatory-Medical-Care-Survey-NAMCS-tables.html
Example-Residential-Care-Community-Services-User-NSLTCP-RCC-SU-report: Example-Residential-Care-Community-Services-User-NSLTCP-RCC-SU-report.html
surveytable: surveytable.html
last_built: 2024-07-18T16:51Z
last_built: 2024-07-18T20:49Z
urls:
reference: https://cdcgov.github.io/surveytable/reference
article: https://cdcgov.github.io/surveytable/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/namcs2019sv.html

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

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion man/namcs2019sv.Rd

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

4 changes: 2 additions & 2 deletions vignettes/Advanced-topics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Forwards flow:

Backwards flow:

* Going from (3) to (2): package users typically do not need to do this.
* Going from (3) to (2): you probably don't need this, but see below. If you really need this, call `surveytable:::.load_survey()`.
* Going from (2) to (1): call `saveRDS()`. Normally, you probably don't want to do this. Normally, the survey file (`mysurvey.rds`) should probably not be changed.

The functions for modifying or creating variables that are part of the `surveytable` package (like `var_cut()` or `var_collapse()`) modify (3). Since (3) is what `surveytable` works with and tabulates, you can call `var_collapse()`, and then you can call `tab()`. You don't need to do anything extra in between.
Expand All @@ -96,5 +96,5 @@ If you are modifying the `variables` data frame directly, you are actually modif

Thus, any time you modify `variables` yourself, call `set_survey()`. You modify (2), then copy (2) -> (3) by calling `set_survey()`.

On the flip side, the changes that you make in (3) (using `surveytable` functions like `var_cut()` or `var_collapse()`) are not reflected in (2). If you make changes in (3), then call `set_survey()`, **those changes are lost**, because `set_survey()` copies (2) -> (3). If those changes were important, you can just rerun the code that created them.
On the flip side, the changes that you make in (3) (using `surveytable` functions like `var_cut()` or `var_collapse()`) are not reflected in (2). If you make changes in (3), then call `set_survey()`, **those changes are lost**, because `set_survey()` copies (2) -> (3). If those changes were important, you can just rerun the code that created them. If you really need to go from (3) to (2), use `mysurvey = surveytable:::.load_survey()`.

0 comments on commit afe38a3

Please sign in to comment.