Overview
teal.code
is an R library providing tools to store code and an execution environment associated with it. The features include:
- the
qenv
class for tracking code and storing variables that integrates well withshiny
reactive expressions for use inshiny
applications whose outputs require reproducibility (i.e. the code used in the application can be retrieved and rerun) - ability to chain and join
qenv
objects together to provide fine-grained control over executed code - automatic handling of errors and warnings encountered when executed code
Installation
# stable versions
install.packages('teal.code')
# install.packages("pak")
pak::pak("insightsengineering/teal.code@*release")
Alternatively, you might want to use the development version available on r-universe.
# beta versions
install.packages('teal.code', repos = c('https://pharmaverse.r-universe.dev', getOption('repos')))
# install.packages("pak")
pak::pak("insightsengineering/teal.code")
Usage
To understand how to use this package, please refer to the Getting Started article, which provides multiple examples of code implementation.
Below is the showcase of the example usage
library(teal.code)
my_qenv <- qenv() |> eval_code("x <- 5")
my_qenv
#> <environment: 0x00000225cc85c7a0> [L]
#> Parent: <environment: package:teal.code>
#> Bindings:
#> • x: <dbl> [L]
get_env(my_qenv)
#> <environment: 0x00000225cc85c7a0>
ls(get_env(my_qenv))
#> [1] "x"
qenv_2 <- eval_code(my_qenv, "y <- x * 2") |> eval_code("z <- y * 2")
qenv_2
#> <environment: 0x00000225ca866d68> [L]
#> Parent: <environment: package:teal.code>
#> Bindings:
#> • x: <dbl> [L]
#> • y: <dbl> [L]
#> • z: <dbl> [L]
get_env(qenv_2)
#> <environment: 0x00000225ca866d68>
ls(get_env(qenv_2))
#> [1] "x" "y" "z"
qenv_2[["y"]]
#> [1] 10
Getting help
If you encounter a bug or have a feature request, please file an issue. For questions, discussions, and updates, use the teal
channel in the pharmaverse
slack workspace.