rave-validate: Validate rave data and other conditions

Description Usage Arguments Details Examples

Description

For 'RAVE' modules, you always need to check if data is available or missing before initializing the inputs.

Usage

1
2
3
rave_validate(checks, onfailure, onload, ...)

rave_needs(expr, label, env = parent.frame())

Arguments

checks

function checking whether data is missing; see details and examples

onfailure

function to call once checks fails, defines user interface for user inputs

onload

load data for modules: function to call once checks fails, users finish input forms and decide to load data

...

variables to set under debug mode

expr

expression returning TRUE/FALSE or throwing error ( meaning fail the test) indicating whether data needed is missing

label

message to convey to user if data failed validation test

env

environment to evaluate expr

Details

rave_validate should be called in 'comp.R', rave_needs functions within checks function.

checks, onfailure, and onload are functions taking three arguments: session_data, package_data, and global_data. session_data stores temporary data, package_data stores module and package data, global_data shares some global settings. checks function needs to validate data and find if data is missing. rave_needs will capture the failed validations. If one or more tests fail, function onfailure will be called to generate loading user interface. Users are required to enter information required for the missing data. Once all information is collected, onload will be called to load data.

... are key-value pairs for debug mode. There are two purposes for these variables. The first usage is in debug mode, there will be no user interface popping up to load any data. Instead, those key-value pairs will be "fake" inputs stored in package_data. The second usage is in the run-time, the keys work as indicator to store the actual input values (input[[key]]) to package_data for further use, for example, by onload

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## Not run: 

# Running this block of code directly will result in an error
# you need to run in RAVE application or in debug mode
# to enter debug mode, open RAVE module packages in rstudio as a project
# run `rave_context('rave_module_debug', package = <your package>)`

# A validation of whether project is chosen
rave_validate(
  checks = function(session_data, package_data, global_data){
    loaded_project <- package_data$project_name
    rave_needs(isTRUE(loaded_project %in% get_projects()),
               label = 'Project name is missing')
  },
  onfailure = function(session_data, package_data, ...){
    all_projects <- get_projects()

    ui <- tagList(
      selectInput(ns('project_name'), 'Select a project',
                  choices = all_projects,
                  selected = package_data$project_name)
    )

    observeEvent(input$project_name, {
      print(sprintf('switch to project %s ?', input$project_name))
    }, ignoreInit = FALSE, ignoreNULL = TRUE)

    list(ui = ui)
  },
  onload = function(session_data, package_data, ...){
    # use information from `onfailure` to make sure `checks` passes
    # nothing to do because `project_name` has been stored to `package_data`
  },

  # Indicating `project_name` is an input and need to be stored in
  # package_data During debug mode, package_data$project_name will be
  # assigned with 'test'
  project_name = 'test'
)


## End(Not run)

dipterix/rave2 documentation built on Sept. 1, 2020, 12:07 a.m.