Skip to content

Commit

Permalink
Issue 2427 first serious attempt for example_qs.rda, see comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jimrothstein committed Aug 23, 2024
1 parent 95b4eca commit 2bd4290
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
11 changes: 4 additions & 7 deletions data-raw/example_qs.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Code to create `example_qs.rda` dataset and save it in data/
## This replaces inst/example_scripts/example_qs.R
## Follows the same standard as pharmaversesdtm
## Follows the same standard as pharmaversesdtm


library(dplyr)
library(admiraldev)
# nolint start
suppress_warning(
qs_gad7 <- tibble::tribble(
Expand Down Expand Up @@ -207,9 +208,5 @@ example_qs <- bind_rows(qs_gad7, qs_gdssf, qs_sp) %>%
STUDYID = "STUDYX",
.before = everything()
)

## TO BE REMOVED
#save(example_qs, file = file.path("data", "example_qs.rda"), compress = "bzip2")

example_qs_new=example_qs
usethis::use_data(example_qs_new, overwrite = TRUE)
# create example_qs.rda in data/
usethis::use_data(example_qs, overwrite = TRUE)
27 changes: 17 additions & 10 deletions data-raw/test.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@

#
# Test:
# In folder data/ files should contain identical R objects:
# Newly created *.rda files in folder data/ MUST BE IDENTICAL to old_data/*.rda

# example_qs.rda was created in via script inst/example_scripts/example_qs.R
# example_qs_new.rda was created by NEWER method, script data-raw/example_qs_new.R
# *.rda file in old_data/ is copy of file created in via script inst/example_scripts/example_qs.R

# Run both methods, create the 2 *.rda files:
source("data-raw/example_qs.r")
source("inst/example_scripts/example_qs.R")
source("data-raw/example_qs.R") # new
source("inst/example_scripts/example_qs.R") # old


## Please restart R or remove objects in environment

# load stored objects into environment
# original method
# Load stored objects into environments
# Because `load` places objects in current environment, put old_data in a new environment

# For created data, place object into current_env
load("data/example_qs.rda")

# newer method
load("data/example_qs_new.rda")
# But create new environment for old_data/
e <- new_environment()
load("old_data/example_qs.rda", envir = e)


# test
identical(example_qs, e$example_qs)

identical(example_qs_new, example_qs)
# cleanup: remove e
rm(e)
Binary file added old_data/example_qs.rda
Binary file not shown.

0 comments on commit 2bd4290

Please sign in to comment.