Skip to content

Commit

Permalink
Closes #5 split ae into ae_ophtha and ae. (#40)
Browse files Browse the repository at this point in the history
* #5 split ae into `ae_ophtha` and `ae`.

* #5 chore: spelling and code style
  • Loading branch information
manciniedoardo authored Aug 1, 2023
1 parent 36bb03f commit 7b70792
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 21 deletions.
7 changes: 7 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#' @source \url{https://github.com/pharmaverse/admiral.test/blob/main/data/admiral_ae.rda}
"ae"

#' Ophthalmology Adverse Events Dataset
#'
#' An example Adverse Events SDTM dataset with ophthalmology-specific variable `AELAT`
#'
#' @source Constructed using `ae` from the `{pharmaversesdtm}` package # nolint
"ae_ophtha"

#' Concomitant Medication Dataset
#'
#' A SDTM CM dataset from the CDISC pilot project
Expand Down
22 changes: 2 additions & 20 deletions data-raw/ae.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
# Update AE by adding AELAT variable for admiraloptha package

# from CDISC pilot study ----
library(dplyr)
library(admiral)
library(metatools)
library(haven)
library(admiral)

raw_ae <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/ae.xpt?raw=true") # nolint
raw_suppae <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/suppae.xpt?raw=true") # nolint
ae <- convert_blanks_to_na(raw_ae)
suppae <- convert_blanks_to_na(raw_suppae)

# create possible AELAT values - as collected on CRF ----
lat <- c("LEFT", "RIGHT", "BOTH")

# create AELAT variable ----
# with random assignment of lat values where AESOC is "EYE DISORDERS"
# Set seed so that result stays the same for each run
set.seed(1)
ae$AELAT <- if_else(ae$AESOC == "EYE DISORDERS",
apply(ae, 1, function(x) sample(lat, 1)),
NA_character_
)
admiral_ae <- ae %>%
add_labels(AELAT = "Laterality")

attr(admiral_ae, "label") <- "Adverse Events"

# Save dataset ----
ae <- admiral_ae
save(ae, file = "data/ae.rda", compress = "bzip2")
usethis::use_data(suppae, overwrite = TRUE)
30 changes: 30 additions & 0 deletions data-raw/ae_ophtha.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Update AE by adding AELAT variable for admiralophtha package
library(dplyr)
library(admiral)
library(metatools)
library(haven)

# Start from standard AE dataset from this package - this should be
# in the environment already if devtools::load_all() has been run
ae_ophtha <- ae

# create possible AELAT values - as collected on CRF ----
lat <- c("LEFT", "RIGHT", "BOTH")

# create AELAT variable ----
# with random assignment of lat values where AESOC is "EYE DISORDERS"
# Set seed so that result stays the same for each run
set.seed(1)

ae_ophtha$AELAT <- if_else(ae_ophtha$AESOC == "EYE DISORDERS",
apply(ae_ophtha, 1, function(x) sample(lat, 1)),
NA_character_
)

ae_ophtha <- ae_ophtha %>%
add_labels(AELAT = "Laterality")

attr(ae_ophtha, "label") <- "Adverse Events"

# Save dataset ----
save(ae_ophtha, file = "data/ae_ophtha.rda", compress = "bzip2")
Binary file modified data/ae.rda
Binary file not shown.
Binary file added data/ae_ophtha.rda
Binary file not shown.
Binary file modified data/suppae.rda
Binary file not shown.
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ADEG
ADaM
AE
AELAT
Arancibia
CDISC
Changelog
Expand Down Expand Up @@ -34,6 +35,7 @@ SV
TAs
USUBJIDs
VFQ
ae
admiraldata
admiraltemplate
admiralxxx
Expand Down
2 changes: 1 addition & 1 deletion man/ae.Rd

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

19 changes: 19 additions & 0 deletions man/ae_ophtha.Rd

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

0 comments on commit 7b70792

Please sign in to comment.