zoonproject / zoon

The zoon R package
Other
61 stars 13 forks source link

better print.zoonWorkflow #370

Open goldingn opened 7 years ago

goldingn commented 7 years ago

Posting for @lizhmartin. The default print method for zoonWorkflow objects is kind of icky:

library(zoon)
Carolina_Wren_Workflow <- workflow(occurrence = CarolinaWrenPO,
                                   covariate = CarolinaWrenRasters,
                                   process = Background(100),
                                   model = LogisticRegression,
                                   output = PrintMap)

## same as
# zoon:::print.zoonWorkflow(Carolina_Wren_Workflow)
Carolina_Wren_Workflow
zoonWorkflow Object
===================

  Call: workflow(occurrence = CarolinaWrenPO, covariate = CarolinaWrenRasters, process = Background(100), model = LogisticRegression, output = PrintMap, forceReproducible = FALSE) 

Some formatting of the call would be helpful, or better yet a more structured list of the modules used

goldingn commented 7 years ago

E.g. something like this:

cl <- Carolina_Wren_Workflow$call.list
names <- c('occurrence', 'covariate', 'process', 'model', 'output')
for (i in 1:5) {
  cat(sprintf('%s:\n', names[i]))
  module_list <- cl[[i]]
  for (j in seq_along(module_list)) {
    module <- module_list[[j]]
    if (isTRUE(all.equal(module$paras, list()))) {
      cat(sprintf('\t%s', module$module))
    } else {
      args <- paste(names(module$paras), module$paras, sep = ' = ')
      cat(sprintf('\t%s(%s)',
                  module$module,
                  paste(args, collapse = ', ')))
    }
    cat('\n')
  }
}
occurrence:
    CarolinaWrenPO
covariate:
    CarolinaWrenRasters
process:
    Background(n = 100)
model:
    LogisticRegression
output:
    PrintMap

but handling chains, lists, unnamed arguments etc.

AugustT commented 7 years ago

Looks good to me. It think we want print to return something short and simple as plot and summary do more extensive stuff. what you suggest does this nicely