eCerto_R6Class {eCerto}R Documentation

A reactive class based on an R6 object.

Description

Builds a class, which allows only restricted access to the contained 'reactiveValues'. Elements should be accessed via getValue(). Possible advantages are that (1) structure of 'reactiveValues' is clear from the beginning (no function like "addVariable" should exist!) and that (2) functions to calculate the mean or plot current data can be implemented here directly.

General access to data object (so data object can maybe get changed without that much code edit)

Returns element. If 'key' is used, reactivity not working correctly. Preferable way for calling getValue(df, key), see example

Usage

setValue(df, key, value)

getValue(df, key = NULL)

Arguments

df

An object of class R6.

key

Key value within R6 object 'df'.

value

Value to set.

Value

Nothing. The R6 object is updated automatically.

Value of 'key' from 'df'.

Active bindings

cur_an

Set or return the current analyte (reactiveVal) via an active binding.

Methods

Public methods


Method new()

Write the (reactive) value of element 'keys' from list 'l'.

Usage
eCerto$new(rv)
Arguments
rv

'reactiveValues' object.

Returns

A new 'eCerto' object.


Method get()

Read the value of field element of R6 object.

Usage
eCerto$get(keys = NULL)
Arguments
keys

Name of list element.

Returns

Current value of field.


Method set()

Set element of R6 object defined by 'keys' to new value.

Usage
eCerto$set(keys = NULL, value)
Arguments
keys

Name(s) of list element.

value

New value.

Returns

New value of element (invisible).


Method c_plot()

Plot the certification data either provided by the user or from the private slot of self.

Usage
eCerto$c_plot(data, annotate_id = FALSE, filename_labels = FALSE)
Arguments
data

data.frame containing columns 'value', 'Lab' and 'L_flt' for a specific analyte.

annotate_id

T/F to overlay the plot with ID as text if column 'ID' is present.

filename_labels

T/F to use imported file names as labels on x-axes.

Returns

A plot.


Method c_lab_means()

Compute the analyte means for a data set filtered for a specific analyte.

Usage
eCerto$c_lab_means(data)
Arguments
data

data.frame containing columns 'analyte', 'value', 'Lab', 'S_flt' and 'L_flt'.

Returns

A data.frame of lab means.


Method c_analytes()

Return analyte names currently in apm.

Usage
eCerto$c_analytes()
Returns

A named character vector.


Method c_lab_codes()

Return lab codes currently in C data.

Usage
eCerto$c_lab_codes()
Returns

A named character vector.


Method a_p()

Return currently specified values of a type for all analytes.

Usage
eCerto$a_p(
  val = c("precision", "precision_export", "pooling", "confirmed", "unit", "name")
)
Arguments
val

A character value indicating the item of the apm list to be extracted

Returns

A named vector.


Method e_present()

Return modules with existing data.

Usage
eCerto$e_present()
Returns

A named logical vector.


Method c_fltData()

Filter the full data set for a specific analyte and remove all 'S_flt' but keep 'L_flt'.

Usage
eCerto$c_fltData(recalc = FALSE)
Arguments
recalc

If TRUE triggers a recalculation and returns current object if FALSE..

Returns

A data.frame with filtered data of a single analyte.


Method clone()

The objects of this class are cloneable with this method.

Usage
eCerto$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


if (interactive()) {
  # establish new Shiny session and new eCerto object
  ShinySession <- shiny::MockShinySession$new()
  test <- eCerto::eCerto$new()
  # view current value stored in specific eCerto slot and register observer
  shiny::isolate(eCerto::getValue(test, c("Certification", "data")))
  shiny::observeEvent(eCerto::getValue(test, c("Certification", "data")), {
    message("Certification$data changed:", eCerto::getValue(test, "Certification")$data)
  })
  # change value of specific eCerto slot and flush reactivity to trigger observer
  shiny::isolate(eCerto::setValue(test, c("Certification", "data"), 5))
  ShinySession$flushReact()
  shiny::isolate(eCerto::getValue(test, c("Certification", "data")))
}
tmp <- eCerto$new()
shiny::isolate(tmp$c_plot())
shiny::isolate(tmp$c_lab_means())
tmp$c_analytes()
tmp$c_lab_codes()
tmp$a_p()
tmp$a_p("pooling")
ca <- shiny::isolate(tmp$cur_an)
tmp$a_p("pooling")[ca]
shiny::isolate(tmp$e_present())
tmp$c_fltData()
shiny::isolate(tmp$cur_an <- "Fe")
shiny::isolate(tmp$cur_an)
tmp$c_fltData()
x <- shiny::isolate(eCerto::getValue(tmp, c("General", "apm")))
x[[shiny::isolate(tmp$cur_an)]][["lab_filter"]] <- "L2"
shiny::isolate(eCerto::setValue(tmp, c("General", "apm"), x))
tmp$c_fltData()
tmp$c_fltData(recalc = TRUE)

# Only run examples in interactive R sessions
if (interactive()) {
  rv <- eCerto$new(init_rv())
  setValue(rv, c("Certification", "data"), 5)
  getValue(rv, c("Certification", "data")) # is 5?
  setValue(rv, c("General", "user"), "Franz")
  getValue(rv, c("General", "user"))
}

[Package eCerto version 0.5.14 Index]