eCerto_R6Class {eCerto} | R Documentation |
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
setValue(df, key, value)
getValue(df, key = NULL)
df |
An object of class R6. |
key |
Key value within R6 object 'df'. |
value |
Value to set. |
Nothing. The R6 object is updated automatically.
Value of 'key' from 'df'.
cur_an
Set or return the current analyte (reactiveVal) via an active binding.
new()
Write the (reactive) value of element 'keys' from list 'l'.
eCerto$new(rv)
rv
'reactiveValues' object.
A new 'eCerto' object.
get()
Read the value of field element of R6 object.
eCerto$get(keys = NULL)
keys
Name of list element.
Current value of field.
set()
Set element of R6 object defined by 'keys' to new value.
eCerto$set(keys = NULL, value)
keys
Name(s) of list element.
value
New value.
New value of element (invisible).
c_plot()
Plot the certification data either provided by the user or from the private slot of self.
eCerto$c_plot(data, annotate_id = FALSE, filename_labels = FALSE)
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.
A plot.
c_lab_means()
Compute the analyte means for a data set filtered for a specific analyte.
eCerto$c_lab_means(data)
data
data.frame containing columns 'analyte', 'value', 'Lab', 'S_flt' and 'L_flt'.
A data.frame of lab means.
c_analytes()
Return analyte names currently in apm.
eCerto$c_analytes()
A named character vector.
c_lab_codes()
Return lab codes currently in C data.
eCerto$c_lab_codes()
A named character vector.
a_p()
Return currently specified values of a type for all analytes.
eCerto$a_p( val = c("precision", "precision_export", "pooling", "confirmed", "unit", "name") )
val
A character value indicating the item of the apm list to be extracted
A named vector.
e_present()
Return modules with existing data.
eCerto$e_present()
A named logical vector.
c_fltData()
Filter the full data set for a specific analyte and remove all 'S_flt' but keep 'L_flt'.
eCerto$c_fltData(recalc = FALSE)
recalc
If TRUE triggers a recalculation and returns current object if FALSE..
A data.frame with filtered data of a single analyte.
clone()
The objects of this class are cloneable with this method.
eCerto$clone(deep = FALSE)
deep
Whether to make a deep clone.
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"))
}