Skip to content

Commit

Permalink
CAUTION: cache location has changed; This code has not been well tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimrothstein committed Oct 8, 2024
1 parent 91c5934 commit bba42c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 76 deletions.
29 changes: 1 addition & 28 deletions data-raw/create_admiral_adlb.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,4 @@ admiral_adlb
#
# Finally, save reduced ds
#
use_data(admiral_adlb, overwrite = TRUE)

#
# TEST - is dataset identical to .... backup of unaltered dataset
#
e1 <- new.env()
e2 <- new.env()
load("data/admiral_adlb.rda", e1)

# CHANGE to YOUR location of original dataset
load("data-backup/admiral_adlb.rda", e2)

# compare field names
t <- tibble(e1 = names(e1$admiral_adlb), e2 = names(e2$admiral_adlb))
t |> print(n = 111)

identical(e1$admiral_adlb, e2$admiral_adlb)
diffdf(e1$admiral_adlb, e2$admiral_adlb)

## Capture diffdf to file

capture.output(
diffdf(
compare = e1$admiral_adlb, base = e2$admiral_adlb,
keys = c("STUDYID", "DOMAIN", "USUBJID", "AVAL", "VISIT")
),
file = "data-raw/diffdf_adlb_23SEPT"
)
usethis::use_data(admiral_adlb, overwrite = TRUE)
52 changes: 4 additions & 48 deletions data-raw/create_admiral_adsl.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Create dataset: data/admiral_adsl.rda
# This script: create_admiral_adsl.R creates dataset data/admiral_adsl.rda.
# This script, create_admiral_adsl.R, creates dataset data/admiral_adsl.rda.
#

# Preliminary
library(diffdf) # nolint


#
# nolint start: object_name_linter.
# To clarify directories (can be removed)
CACHE_DIR <- "~/.cache/R/admiral_templates_data/"
CACHE_DIR <- "~/.config/cache/R/admiral_templates_data/"
DATA_DIR <- "data-dir"
DATA_RAW <- "data-raw"
TEMPLATE_DIR <- "inst/templates/"
Expand All @@ -25,27 +23,6 @@ if (file.exists(THE_FILE)) file.remove(THE_FILE)
# First, use template to create the R script (in data-raw/admiral_adlb.R).
# Next, source this script and create the data (~/.cache/R/admiral_template_data/admiral_adlb.rda)
# Finally, shorten this data (now ~ 1.2 MB) by selecting only certain USUBJID

# OMIT -- orignal method - OMIT
if (FALSE) {
# ### original mehtod (method 1)
# # First, create the R script (from a template)
adam_name <- "adlb"
save_path <- paste0("./data-raw/admiral_", adam_name, ".R")
use_ad_template(
adam_name = adam_name,
save_path = save_path,
open = FALSE,
overwrite = TRUE
)
# Second, source the script and save data in .cache
source("data-raw/admiral_adlb.R") # nolint
load("~/.cache/R/admiral_templates_data/adlb.rda")
}

#
#
# Instead, USE template, as recommened by Buzz
#
source(paste0(TEMPLATE_DIR, "/ad_adsl.R")) # nolint
load(paste0(CACHE_DIR, "adsl.rda"))
Expand All @@ -54,25 +31,4 @@ admiral_adsl <- adsl
#
# Finally, save reduced ds
#
use_data(admiral_adsl, overwrite = TRUE)

#
# TEST - is dataset identical to .... backup of unaltered dataset
#
e1 <- new.env()
e2 <- new.env()
load("data/admiral_adsl.rda", e1)

# CHANGE to YOUR location of original dataset
load("data-backup/admiral_adsl.rda", e2)


identical(e1$admiral_adsl, e2$admiral_adsl)
diffdf(compare = e1$admiral_adsl, base = e2$admiral_adsl, keys = c("STUDYID", "USUBJID"))
capture.output(
diffdf(
compare = e1$admiral_adsl, base = e2$admiral_adsl,
keys = c("STUDYID", "USUBJID")
),
file = "data-raw/diffdf_23SEPT"
)
usethis::use_data(admiral_adsl, overwrite = TRUE)

0 comments on commit bba42c8

Please sign in to comment.