Skip to content

Commit

Permalink
Cleaned create_admiral_adlb.R code. Calls template, then script to ge…
Browse files Browse the repository at this point in the history
…nerate admiral_adlb.rda

Finally, checks new and old admiral_adlb.rda are IDENTICAL.
  • Loading branch information
jimrothstein committed Sep 10, 2024
1 parent d79b080 commit 48f8934
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions data-raw/create_admiral_adlb.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This is a MULTI-step process.

# First, using template to create the R script (in data-raw/admiral_adlb.R) which will generate the data.
# First, using 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 USERJID

Expand All @@ -19,41 +19,60 @@ use_ad_template(
)

# Second, source the script and save data in .cache
source("data-raw/admiral_adlb.R") # nolint
source("data-raw/admiral_adlb.R") # nolint

# Load the data into .GlobalEnv
load("~/.cache/R/admiral_templates_data/adlb.rda" )
load("~/.cache/R/admiral_templates_data/adlb.rda")

#nrow(adlb) 83,652
# nrow(adlb) 83,652

# limit rows, by selecting only these USUBJID
#' 01-701-1015, 01-701-1023, 01-701-1028, 01-701-1033,
#' 01-701-1034, 01-701-1047, 01-701-1097, 01-705-1186,
#' 01-705-1292, 01-705-1310, 01-708-1286

USUBJID =
c("01-701-1015",
"01-701-1023",
"01-701-1028",
"01-701-1033",
"01-701-1034",
"01-701-1047",
"01-701-1097",
"01-705-1186",
"01-705-1292",
"01-705-1310",
"01-708-1286"
)
usubjid <-
c(
"01-701-1015",
"01-701-1023",
"01-701-1028",
"01-701-1033",
"01-701-1034",
"01-701-1047",
"01-701-1097",
"01-705-1186",
"01-705-1292",
"01-705-1310",
"01-708-1286"
)

# prepare for inner join
user = tibble(
USUBJID = USUBJID)
user <- tibble(
USUBJID = usubjid
)

result = inner_join(adlb,user)
admiral_adlb = result
result <- inner_join(adlb, user)
admiral_adlb <- result

# check
#USUBJID %in% result$USUBJID
# USUBJID %in% result$USUBJID

# Finally, saved reduced ds
# 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)

identical(e1$admiral_adsl, e2$admiral_adsl)

# cleanup
rm(e1)
rm(e2)

0 comments on commit 48f8934

Please sign in to comment.