rave_context_generics: Create S3 Generic Functions that Respects RAVE Context

Description Usage Arguments Value See Also Examples

View source: R/aaa_context.R

Description

Create S3 Generic Functions that Respects RAVE Context

Usage

1
rave_context_generics(fun_name, args = alist(), env = parent.frame())

Arguments

fun_name

generic function name

args

list of arguments to the function. Use alist

env

in which environment the function is declared.

Value

A generic function.

See Also

rave-context

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Make a generic function that reacts under different contexts
# The goal is to ask user a comple question. Under debug mode,
# Ignore the question and always answer "Yes"
ask_for_input <- rave_context_generics(
  'ask_for_input', args = alist(msg =, ...=))

# write default action. Since under default context, shiny is not running
ask_for_input.default <- function(msg, ...){
  utils::askYesNo(msg)
}

ask_for_input.rave_module_debug <- function(msg, ...){
  # Do not prompt questions and always answer yes
  return(TRUE)
}

if(interactive()){
  rave_context('default')

  # will prompt for answer
  ask_for_input('Answer yes or no')
}

# When debugging modules
rave_context('rave_module_debug', package = 'base')
ask_for_input('Answer yes or no')  # always returns TRUE

dipterix/raveutils documentation built on July 6, 2020, 12:24 a.m.