teal.code
is an R library providing tools to store code
and an execution environment associated with it. The features
include:
qenv
for storing code and an execution
environment which integrates well with shiny reactives
for
use in shiny
applications whose outputs require
reproducibility (i.e. the code used to generate them)qenv
objects together to
provide fine-grained control over executed codeteal.code
also ships a shiny
module that helps
inspect the stored code as well as messages, warnings and error messages
resulting from evaluation via shiny
web application.
From July 2023 insightsengineering
packages are
available on r-universe.
# stable versions
install.packages('teal.code', repos = c('https://insightsengineering.r-universe.dev', 'https://cloud.r-project.org'))
# install.packages("pak")
::pak("insightsengineering/teal.code@*release") pak
Alternatively, you might also use the development version.
# beta versions
install.packages('teal.code', repos = c('https://pharmaverse.r-universe.dev', 'https://cloud.r-project.org'))
# install.packages("pak")
::pak("insightsengineering/teal.code") pak
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)
<- new_qenv(env = list2env(list(x = 5)), code = "x <- 5")
my_qenv
my_qenv#> Parent: <environment: package:teal.code>
#> Bindings:
#> • x: <dbl> [L]
<- eval_code(my_qenv, "y <- x * 2") |> eval_code("z <- y * 2")
qenv_2
qenv_2#> <environment: 0x00000135b544cfe8> [L]
#> Parent: <environment: package:teal.code>
#> Bindings:
#> • x: <dbl> [L]
#> • y: <dbl> [L]
#> • z: <dbl> [L]
"y"]]
qenv_2[[#> [1] 10
cat(paste(get_code(qenv_2), collapse = "\n"))
#> x <- 5
#> y <- x * 2
#> z <- y * 2
If you encounter a bug or you have a feature request - please file an
issue. For questions, discussions and staying up to date, please use the
“teal” channel in the pharmaverse
slack
workspace.