R/generateParameterKey.R

Defines functions generateParameterKey

# Function to generate a key matching Module objects with Task objects and their respective parameters
# 
# More detailed explaination here
# 
# @param pipeline An object of class \code{Pipeline}
# 
# @return A named list of lists where the name of each parent corresponds to a module in \code{pipeline} and each child corresponds to a task within that module
# 
# @examples
# \dontrun{
# generateParameterKey(pipeline)
# }
# @keywords internal

generateParameterKey <- function(pipeline){
  
  # count the tasks
  task.count <- countTasks(pipeline)
  
  # set up the parameter key
  parameter.key <- list()
  for(label in names(task.count)){
    parameter.key[[label]] <- as.list(rep(NA,task.count[label]))
  }
  
  # loop through each module & task, adding all task parameters to the key
  for(module in pipeline$modules){
    counter <- 0
    for(task in module$tasks){
      o <- expand.grid(task$control,stringsAsFactors=F)
      if(nrow(o)==0){
        counter <- counter + 1
        task.parameters <- as.list(formals(task$method))
        parameter.key[[module$label]][[counter]] <- task.parameters
      } else {
        for(i in 1:nrow(o)){
          counter <- counter + 1
          task.parameters <- as.list(formals(task$method))
          task.parameters[names(o)] <- o[i,]
          parameter.key[[module$label]][[counter]] <- task.parameters
        }
      }
    }
  }
  
  # return the parameter key
  return(parameter.key)
  
}
jperezrogers/rabbit documentation built on Feb. 9, 2020, 4:59 p.m.