R/qa_which_resmod_folders.R

Defines functions which_resmod_folders

Documented in which_resmod_folders

#' Get all idv names. Idv name will be collected from the resmod_'idv' folder name.
#'
#' @param directory The qa run directory path.
#' @param idv_name The string of the idv name from the -idv option in the qa run.
#' @param quiet A logical indicating whether function should not write the warning message
#' if some file not found. By default quiet=FALSE.
#'
#' @return Character vector with all idv names.
#' @export
which_resmod_folders <- function(directory,idv_name,quiet=F) {
  #get resmod folder suffix
  resmod_suffix <- list.files(directory) %>%
    .[grep("^resmod_",.)] %>%
    sub('.*resmod_','',.)

  #order TIME,TAD,PRED
  order <- c(idv_name,"TAD","PRED")
  order <- unique(order)

  all_idvs <- c()
  j <- 1
  for (i in 1:length(order)) {
    if(any(resmod_suffix==order[i])) {
      all_idvs[j] <- order[i]
      j <- j + 1
    }
  }
  #print message if no resmod folders found
  if(is.null(all_idvs) && !quiet) {
    message("WARNING: No RESMOD run folders found in the directory '",directory,"'")
  }

  return(all_idvs)
}
UUPharmacometrics/PsNR documentation built on June 30, 2023, 8:34 a.m.