R Under development (unstable) (2024-02-16 r85931 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("R.rsp") R.rsp v0.46.0 successfully loaded. See ?R.rsp for help. > > ## Report template > report <- function() { + cat("Report:\n") + cat(sprintf("a=%g\n", a)) + cat("------\n") + } # report() > > > ## 1. Generate report() > a <- 1 > s <- rstring(report) > cat(s) Report: a=1 ------ > a <- 2 > rcat(report) Report: a=2 ------ > a <- 3 > dummy <- rfile(report, output="") Report: a=3 ------ > > > ## 2. Generate report() in custom environment > env <- new.env() > env$a <- 1 > s <- rstring(report, envir=env) > cat(s) Report: a=1 ------ > > env$a <- 2 > rcat(report, envir=env) Report: a=2 ------ > > env$a <- 3 > dummy <- rfile(report, output="", envir=env) Report: a=3 ------ > > > > ## 3. Generate report() within another function > foo <- function() { + a <- 1 + s <- rstring(report) + cat(s) + a <- 2 + rcat(report) + a <- 3 + dummy <- rfile(report, output="") + } # foo() > > foo() Report: a=1 ------ Report: a=2 ------ Report: a=3 ------ > > proc.time() user system elapsed 0.32 0.03 0.34