Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 qs ophtha@devel #45

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions data-raw/qs_ophtha.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
library(dplyr)
library(stringr)
data("qs")
library(metatools)
library(haven)
library(admiral)


# from CDISC pilot study ----
sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint
raw_qs <- read_xpt(paste0(sdtm_path, "qs", ".xpt?raw=true")) %>%
convert_blanks_to_na()


# set seed to get same results each run
set.seed(999)

# add vfq data
# create new QS data - keep standard variables from previous ADMIRAL project's QS ====
qs1 <- qs %>%
qs1 <- raw_qs %>%
# select standard variables
select(STUDYID, DOMAIN, USUBJID, QSBLFL, VISITNUM, VISIT, VISITDY, QSDTC, QSDY) %>%
# keep unique subjects and visits per subject
Expand Down Expand Up @@ -124,9 +135,29 @@ qs3 <- qs2 %>%
# NOTE: the QS2 dataset made above should be stacked below the qs dataset.
# output qs_ophtha.RDS
# remove the original vfq part from admiral_qs
admiral_qs_novfq <- qs %>% filter(QSCAT != "NEI VFQ-25")
admiral_qs_novfq <- raw_qs %>% filter(QSCAT != "NEI VFQ-25")

qs_ophtha1 <- rbind(admiral_qs_novfq, qs3)

# --SEQ and keep relevant variables;
qs_ophtha2 <- qs_ophtha1 %>%
select(-QSSEQ) %>%
arrange(STUDYID, USUBJID, QSCAT, QSTESTCD, QSDTC, VISITNUM)

qs_ophtha3 <- qs_ophtha2 %>%
group_by(STUDYID, USUBJID) %>%
mutate(QSSEQ = row_number()) %>%
select(
STUDYID, DOMAIN, USUBJID, QSSEQ, QSTESTCD, QSTEST, QSCAT, QSSCAT, QSORRES, QSORRESU, QSSTRESC, QSSTRESN, QSSTRESU,
QSBLFL, QSDRVFL, VISITNUM, VISIT, VISITDY, QSDTC, QSDY
) %>%
ungroup()

qs_ophtha <- qs_ophtha3

qs_ophtha <- rbind(admiral_qs_novfq, qs3)
# assign dataset label
attr(qs_ophtha, "label") <- "Questionnaires"

# ---- Save output for temporary usage ----
save(qs_ophtha, file = file.path("data", "qs_ophtha.rda"), compress = "bzip2")
# save(qs_ophtha, file = "data/qs_ophtha.rda", compress = "bzip2")
usethis::use_data(qs_ophtha, overwrite = TRUE)
Binary file modified data/qs_ophtha.rda
Binary file not shown.
Loading