Skip to contents

Adds variable of interest to the Recipe

Usage

add_var(rec, var_info)

# S4 method for class 'Recipe'
add_var(rec, var_info)

# S4 method for class 'PrepRecipe'
add_var(rec, var_info)

Arguments

rec

A Recipe object.

var_info

A character string of column names corresponding to variables that will be used in any context.

Value

A Recipe object.

Examples

data(metaHIV_phy)

## Define recipe
rec <- recipe(metaHIV_phy)

## add var info
rec <- add_var(rec, var_info = "RiskGroup2")
rec
#> ── DAR Recipe ──────────────────────────────────────────────────────────────────
#> Inputs:
#> 
#>       phyloseq object with 451 taxa and 156 samples 
#>       variable of interes RiskGroup2 (class: character, levels: hts, msm, pwid) 
#>       undefined taxonomic level. Use add_tax() to add it to Recipe! 
#> 

## add var info to a prep-recipe returns an error
data(test_prep_rec)
err <- testthat::expect_error(
  add_var(test_prep_rec, var_info = "RiskGroup2")
)

err
#> <error/rlang_error>
#> Error in `add_var()`:
#> ! var_info can only be added to a non-PrepRecipe
#> ---
#> Backtrace:
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5. ─pkgdown:::unwrap_purrr_error(...)
#>   6. └─base::withCallingHandlers(...)
#>   7.         └─purrr::map(...)
#>   8.           └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>   9. ─purrr:::with_indexed_errors(...)
#>  10. └─base::withCallingHandlers(...)
#>  11. purrr:::call_with_cleanup(...)
#>  12.             └─pkgdown (local) .f(.x[[i]], ...)
#>  13. base::withCallingHandlers(...)
#>  14.               └─pkgdown:::data_reference_topic(...)
#>  15.                 └─pkgdown:::run_examples(...)
#>  16.                   └─pkgdown:::highlight_examples(code, topic, env = env)
#>  17.                     └─downlit::evaluate_and_highlight(...)
#>  18.                       └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  19. base::withRestarts(...)
#>  20. └─base (local) withRestartList(expr, restarts)
#>  21. ├─base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
#>  22. │ └─base (local) doWithOneRestart(return(expr), restart)
#>  23. └─base (local) withRestartList(expr, restarts[-nr])
#>  24. ├─base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
#>  25. │ └─base (local) doWithOneRestart(return(expr), restart)
#>  26. └─base (local) withRestartList(expr, restarts[-nr])
#>  27. └─base (local) withOneRestart(expr, restarts[[1L]])
#>  28. └─base (local) doWithOneRestart(return(expr), restart)
#>  29. evaluate:::with_handlers(...)
#>  30. ├─base::eval(call)
#>  31. │ └─base::eval(call)
#>  32. └─base::withCallingHandlers(...)
#>  33. ─base::withVisible(eval(expr, envir))
#>  34.                         └─base::eval(expr, envir)
#>  35.                           └─base::eval(expr, envir)
#>  36. testthat::expect_error(add_var(test_prep_rec, var_info = "RiskGroup2"))
#>  37. └─testthat:::expect_condition_matching(...)
#>  38. └─testthat:::quasi_capture(...)
#>  39. ├─testthat (local) .capture(...)
#>  40. │ └─base::withCallingHandlers(...)
#>  41. └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
#>  42. dar::add_var(test_prep_rec, var_info = "RiskGroup2")
#>  43.                             └─dar::add_var(test_prep_rec, var_info = "RiskGroup2")