translate: Translate tags and R code in template

Description Usage Arguments Details Value Author(s) Examples

Description

Evaluate tags and inline or chunks of R code present in general template files to produce variable content depending on some input arguments.

Usage

1
2
3
4
translate(vars, ..., template, drop = FALSE, default = "NULL",
        warn = TRUE, start = "<:", end = ":>", redo = 2,
        envir = new.env(parent = parent.frame()), retrans = 2,
        debug = FALSE)

Arguments

vars

list with named elements containing arbitrary variables to search in templates. To specify variables should be used one of the arguments vars or ... but not both. If both are defined only vars is used.

...

arbitrary variables to search in templates.

template

path to template to evaluate.

drop

drop lines with non evaluated variables? Default to FALSE.

default

default character to translate for not given or missing variables. Default to "NULL" (will appear preceded by "<:" and ":>" or startNULLend in translated file).

warn

print warning if some variables are still not translated in the finel file. Default to TRUE. If FALSE process will stop returning an error.

start

line number where the R code chunk starts, or string to match start of variable. Default to "<:".

end

line number where the R code chunk ends, or string to match end of variable. Default to ":>".

redo

how many times translate? Default to 2 (so variables can appear in definition of other variables and still be translated).

retrans

retranslate a template a number of times.

envir

environment where to evaluate R code.

debug

logical. Default to FALSE (no debug).

Details

The function translate evaluate 'tags' and inline or chunks of R code in a template modifying its content. The tags are calls that point to argument variables which are provided by the user. Thus, the main input arguments for translate are the template (provided as a character vector where each element correspond to a line in the template file) and the variables which will be used to evaluate the tags in the template to update its content. The evaluation is performed in an environment which can also be defined by the user. The output of translate is a character vector where each element correspond to the line of the modified template. The tags names are denoted in betweed <: :>, for example <:tag_name:>, and they must be placed in the position where we want their evaluation to occur and output to appear. We should provide tag_name = value in the arguments of function translate. The inline or chunks of R code must follow the rules set in translate_r_code. See tRnslate package vignette or run vignette(tRnslate). For more details see tmplate package vignette or run vignette("tmplate"). For an example see tmplate-package.

Value

Once tags and the chunks or inline R code are evaluated by translate using the input arguments given, then it returns a character vector where each element corresponds to the original line in the template file where the tags, chunks and inline code has been replaced by its output. This content can be seen in console or written to disc, for example, by using cat (it requires to use sep = "\n").

Author(s)

Mario A. Martinez Araya, r@marioma.me

Examples

1
2
3
4
5
6
7
## To see an example in R console run:
##
## ?tmplate::tmplate
##
## Or See instructions in the following file:
## (example present in the vignette)
source(system.file("examples/example.R", package = "tmplate"))

tmplate documentation built on July 20, 2021, 9:06 a.m.