Can someone help me to setup a function to add supplemental domain into main domain in sdtm
this is my initial code
merge ae with suppae
temp1 <- supp_ae %>%
pivot_wider(id_cols=c(USUBJID, IDVARVAL), names_from = QNAM, values_from=QVAL, values_fill = NULL) %>%
mutate(
AESEQ = as.numeric(IDVARVAL)
)
ae1 <- ae %>%
left_join(temp1, by=join_by(USUBJID,AESEQ)) %>%
select(-IDVARVAL)
below is my function, it does not work, I do not know how to fix it
add_supp <- function(domain){
domain_name <- str_to_upper(substitute(domain))
xxseq <- paste0(domain_name,'SEQ')
temp2 <- eval(parse(text=paste0("SUPP_", domain_name)))
temp2_t <- temp2 %>% pivot_wider(id_cols=c(USUBJID, IDVARVAL), names_from = QNAM, values_from=QVAL) %>%
mutate(
xxseq = as.numeric(IDVARVAL)
)
domain%>%
left_join(temp2_t, by=join_by(USUBJID, xxseq )) %>%
select(-IDVARVAL)
}
AE1 <- add_supp(AE)
if I want to merge CM so I can do
CM1 <- add_supp(CM)
Thanks