Learn R Programming

rscala (version 2.3.5)

strintrplt: String Interpolation with Arbitrary R Code

Description

This function allows a character vector to have arbitrary R code embedded within it. The embedded R code --- placed between ‘@{’ and ‘}’ --- is evaluated by default in the environment from which this function is called (not defined). The result of the function is a character vector in which the embedded R code is replaced by character representations of the results of evaluating the embedded R code.

Usage

strintrplt(snippet,envir=parent.frame())

Arguments

snippet

A character vector of length one which may contain multiple ‘@{RCODE}’ substrings which will be replaced by a character representation of the result of evaluating ‘RCODE’. This character vector may contain many R statements and span multiple lines.

envir

The environment in which to evaluate the embedded R code.

Examples

Run this code
# NOT RUN {
strintrplt('val msg = "Current R version is @{paste0(R.Version()$major,".",R.Version()$minor)}"')
index <- 5
strintrplt('var i = @{index-1}')
# }

Run the code above in your browser using DataLab