Title: | Dynamic Generation of Scientific Reports |
---|---|
Description: | The RSP markup language makes any text-based document come alive. RSP provides a powerful markup for controlling the content and output of LaTeX, HTML, Markdown, AsciiDoc, Sweave and knitr documents (and more), e.g. 'Today's date is <%=Sys.Date()%>'. Contrary to many other literate programming languages, with RSP it is straightforward to loop over mixtures of code and text sections, e.g. in month-by-month summaries. RSP has also several preprocessing directives for incorporating static and dynamic contents of external files (local or online) among other things. Functions rstring() and rcat() make it easy to process RSP strings, rsource() sources an RSP file as it was an R script, while rfile() compiles it (even online) into its final output format, e.g. rfile('report.tex.rsp') generates 'report.pdf' and rfile('report.md.rsp') generates 'report.html'. RSP is ideal for self-contained scientific reports and R package vignettes. It's easy to use - if you know how to write an R script, you'll be up and running within minutes. |
Authors: | Henrik Bengtsson [aut, cre, cph] |
Maintainer: | Henrik Bengtsson <[email protected]> |
License: | LGPL (>= 2.1) |
Version: | 0.45.0 |
Built: | 2023-09-17 05:07:56 UTC |
Source: | https://github.com/HenrikBengtsson/R.rsp |
The RSP markup language makes any text-based document come alive. RSP provides a powerful markup for controlling the content and output of LaTeX, HTML, Markdown, AsciiDoc, Sweave and knitr documents (and more), e.g. 'Today's date is <%=Sys.Date()%>'. Contrary to many other literate programming languages, with RSP it is straightforward to loop over mixtures of code and text sections, e.g. in month-by-month summaries. RSP has also several preprocessing directives for incorporating static and dynamic contents of external files (local or online) among other things. Functions rstring() and rcat() make it easy to process RSP strings, rsource() sources an RSP file as it was an R script, while rfile() compiles it (even online) into its final output format, e.g. rfile('report.tex.rsp') generates 'report.pdf' and rfile('report.md.rsp') generates 'report.html'. RSP is ideal for self-contained scientific reports and R package vignettes. It's easy to use - if you know how to write an R script, you'll be up and running within minutes.
To install this package, call install.packages("R.rsp")
.
We recommend that you start by reading one of the 'vignettes':
A 5 minute slideshow covering the basics of RSP.
Detailed description of the RSP markup language.
A one-page RSP reference card.
How to use RSP for package vignettes.
How to use plain LaTeX for package vignettes.
How to use static PDF or HTML package vignettes.
Then, when you're ready to try it yourself, these are commands you can start with:
Play with rcat
(), which works like cat
() but also processed RSP expressions, e.g. rcat("A random number: <%=sample(100, size=1)%>\n")
.
To source a RSP document as you do with R scripts, use rsource
(), e.g. rsource("report.md.rsp")
which will run the RSP and display the output as it appears.
To compile a RSP document to a final document, use rfile
(), e.g. rfile("report.md.rsp")
outputs Markdown file 'report.md' which is automatically compiled into a final 'report.html'.
Several of the post-processing features of this package utilize packages such as base64enc, knitr, and markdown. Not enough credit can be given to the authors and contributors of those packages. Thank you for your great work.
The releases of this package is licensed under LGPL version 2.1 or newer.
The development code of the packages is under a private licence (where applicable) and patches sent to the author fall under the latter license, but will be, if incorporated, released under the "release" license above.
Bengtsson H (2022). R.rsp: Dynamic Generation of Scientific Reports. R package version 0.44.0-9001, https://github.com/HenrikBengtsson/R.rsp.
Henrik Bengtsson
Evaluates an RSP string and outputs the generated string.
## Default S3 method:
rcat(..., file=NULL, path=NULL, envir=parent.frame(), args="*", output="", buffered=TRUE,
append=FALSE, verbose=FALSE)
## Default S3 method:
rsource(file, path=NULL, envir=parent.frame(), output="", buffered=FALSE, ...)
... |
A |
file , path
|
Alternatively, a file, a URL or a |
envir |
The |
args |
A named |
output |
A |
buffered |
If |
append |
Only applied if |
verbose |
See |
Returns (invisibly) the outputted RspStringProduct
.
Using Rscript
and rcat()
, it is possible to process
an RSP string and output the result from the command line. For example,
Rscript -e "R.rsp::rcat('A random integer in [1,<%=K%>]: <%=sample(1:K, size=1)%>')" --args --K=50
parses and evaluates the RSP string and outputs the result to standard output. A CLI-friendly alternative to the above is:
Rscript -e R.rsp::rcat "A random integer in [1,<%=K%>]: <%=sample(1:K, size=1)%>" --args --K=50
The rsource(file, ...)
is a convenient wrapper
for rcat(file=file, ..., output="", buffered=FALSE)
.
As an analogue, rsource()
is to an RSP file what
source()
is to an R script file.
Henrik Bengtsson
To store the output in a string (instead of displaying it), see
rstring
().
For evaluating and postprocessing an RSP document and
writing the output to a file, see rfile
().
rcat("A random integer in [1,100]: <%=sample(1:100, size=1)%>\n")
# Passing arguments
rcat("A random integer in [1,<%=K%>]: <%=sample(1:K, size=1)%>\n", args=list(K=50))
Evaluates and postprocesses an RSP document and outputs the final RSP document file.
## Default S3 method:
rfile(file, path=NULL, output=NULL, workdir=NULL, type=NA, envir=parent.frame(),
args="*", postprocess=TRUE, ..., verbose=FALSE)
file , path
|
Specifies the RSP file to processed, which can
be a file, a URL or a |
output |
A |
workdir |
The working directory to use after parsing and
preprocessing, but while evaluating and postprocessing
the RSP document.
If argument |
type |
The default content type of the RSP document. By default, it
is inferred from the |
envir |
The |
args |
A named |
postprocess |
If |
... |
Additional arguments passed to the RSP engine. |
verbose |
See |
Returns an RspProduct
.
If argument output
specifies a file, then this is
an RspFileProduct
.
Using Rscript
and rfile()
, it is possible to process
an RSP file from the command line. For example,
Rscript -e "R.rsp::rfile('RSP_refcard.tex.rsp')"
parses and evaluates ‘RSP_refcard.tex.rsp’ and output ‘RSP_refcard.pdf’ in the current directory. A CLI-friendly alternative to the above is:
Rscript -e R.rsp::rfile RSP_refcard.tex.rsp
Henrik Bengtsson
path <- system.file("exData", package="R.rsp")
pathname <- rfile("random.txt.rsp", path=path,
output=file.path(tempdir(), "random.txt"))
print(pathname)
lines <- readLines(pathname, warn=FALSE)
cat(lines, collapse="\n")
file.remove(pathname)
# Passing arguments
path <- system.file("exData", package="R.rsp")
pathname <- rfile("random-args.txt.rsp", path=path, args=list(K=50),
output=file.path(tempdir(), "random-args.txt"))
print(pathname)
lines <- readLines(pathname, warn=FALSE)
cat(lines, collapse="\n")
file.remove(pathname)
## Not run:
# Compile and display the main vignette (requires LaTeX)
if (isCapableOf(R.rsp, "latex")) {
path <- system.file("doc", package="R.rsp")
pdf <- rfile("Dynamic_document_creation_using_RSP.tex.rsp", path=path)
cat("Created document: ", pdf, "\n", sep="")
if (interactive()) browseURL(pdf)
}
## End(Not run)
Evaluates an RSP string and returns the generated string.
## Default S3 method:
rstring(..., file=NULL, path=NULL, envir=parent.frame(), args="*", verbose=FALSE)
... |
A |
file , path
|
Alternatively, a file, a URL or a |
envir |
The |
args |
A named |
verbose |
See |
Returns an RspStringProduct
.
Henrik Bengtsson
To display the output (instead of returning a string), see
rcat
().
For evaluating and postprocessing an RSP document and
writing the output to a file, see rfile
().
x <- rstring("A random integer in [1,100]: <%=sample(1:100, size=1)%>\n")
cat(x)
# Passing arguments
x <- rstring("A random integer in [1,<%=K%>]: <%=sample(1:K, size=1)%>\n", args=list(K=50))
cat(x)