Skip to content
New issue

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

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

Already on GitHub? # to your account

check_rs_rsdtc_visit_ordinal_error() and other --visit_ordinal checks - add logic for missing visit #415

Open
sarabodach opened this issue Sep 11, 2024 · 0 comments · May be fixed by #417 or #424
Open
Labels
update existing check Proposal to refine an existing check function

Comments

@sarabodach
Copy link
Collaborator

check_rs_rsdtc_visit_ordinal_error(rs)
Error in mydf2[!is.na(mydf2$check.flag), ] :
incorrect number of dimensions

Add logic -- see

---- to be added ----####

---- end of to be added ----####

===============


check_rs_rsdtc_visit_ordinal_error <- function(RS){
  
  class(RS) <- 'data.frame'
  vars = c("USUBJID", "VISITNUM", "VISIT", "RSDTC", "RSTESTCD","RSEVAL","RSSTAT")
  
  ### First check that required variables exist and return a message if they don't
  if (RS %lacks_any% vars) {
    
    fail(lacks_msg(RS, vars))
    
    ### Dont run if VISITNUM is all missing
  } else if (length(unique(RS[["VISITNUM"]]))<=1) {
    
    fail("VISITNUM exists but only a single value. ")
    
  } else {
    #only keep INV overall responses not indicated as Not Done
    subsetdf = subset(RS,RS$RSTESTCD=="OVRLRESP" & RS$RSEVAL=="INVESTIGATOR" & RS$RSSTAT != "NOT DONE" & !grepl("UNSCHEDU",toupper(RS$VISIT)),)
    
    #### ---- to be added ----####
    if (length(unique(subsetdf[["VISITNUM"]]))<=1) {
      
      fail("VISITNUM exists but only a single value. ")
      
    } 
    
    #### ---- end of to be added ----####

    else if(nrow(subsetdf)>0){
      
      mydf2 <- dtc_dupl_early(dts = subsetdf, vars = vars,
                              ### groupby variables used for grouping and visit.order derivation
                              groupby = vars[c(1)],
                              dtc = vars[4],
                              ### variables used for ordering before visit.order derivation
                              vars[1], vars[2], vars[3], vars[4])
      
      ### Subset if Vis_order not equal Dtc_order
      myout <- mydf2[!is.na(mydf2$check.flag), ]
      
      ### Different check already doing dups
      myout = subset(myout,myout$check.flag != "Duplicated",)
      
      
      ###Print to report
      
      ### Return message if no records with RSDTC per VISITNUM
      if (nrow(myout) == 0) {
        pass()
        ### Return subset dataframe if there are records with Possible RSDTC data entry error
      } else if (nrow(myout) > 0) {
        rownames(myout) = NULL
        fail(paste("RS has ",nrow(myout)," records with Possible RSDTC data entry error. ",sep = ""), myout)
      }
      
    } else{fail("No records when subset to overall responses by INV. ")}
  }
}

@sarabodach sarabodach added the update existing check Proposal to refine an existing check function label Sep 11, 2024
@AlcJ123 AlcJ123 linked a pull request Oct 8, 2024 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
update existing check Proposal to refine an existing check function
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant