ScriptTemplate: Script template

Description Details See Also

Description

Script templates are a powerful concept in the vartors package. They are script skeletons which will be used to produce usable script thanks to definition of variables.

Details

Script templates should be written in different languages known by R :

R

The classical R language, using file extension .R

R markdown

Used to mix markdown syntax with R code. Use file extension .Rmd. Process these files with knitr

R sweave

Used to mix LaTeX syntax with R code. Process these files with knitr too. No test where done with this format for the moment, because R markdown does almost everything in an easier way.

To be valid, a script template must contain <vartors template> in a comment somewhere in his 5 first lines.

To understand how to read and write a script template, there are two main concepts : blocs and remplacements words

blocs

Blocs are code lines between an opener delimiter and a closer delimiter. Openers are lines starting with #< and closers with #>. These delimiters must have a name recognized by import_template (actually, should be header, footer, integer, numeric, factor, ordered, date or not_used). Only one name by delimiter is allowed. For example, to create a new bloc for factor type, just write :

1
2
3
4
#< factor
# factors must use hist to make nice plots
plot(rep_cleandata$rname)
#> factor

This will add theses lines to the bloc of lines for the factor type

remplacement words

These words will be replaced when create_script will be used. They have a prefix rep_. For example, rep_rname will be replaced by the name of the variable in R from the definition of variables. Actually, usable replacement names are rep_rname, rep_type, rep_description and others ones...

See Also

The main methods are import_template and export_template. They are always used in create_script. To be usable in vartors, a script template must be transformed in a ScriptTemplate object by create_script.


jomuller/vartors documentation built on May 19, 2019, 7:26 p.m.