read.snippet returns pre-defined sections (snippets) of larger source files marked with "tag"-like syntax (e.g., <snippet: label>...</snippet>) Because of the parsing used, it is important that statements end with a semi-colon (;) as is the case with many other programming languages.

read.snippet(..., doc, action)

Arguments

...

(dots_list) Keywords given as strings or symbols for which a matching snippet is sought

doc

The input source document name given as a string: defaults to the active document when the function is invoked with no argument

action

One of goto, skip, parse, exec, save

Value

The snippet text invisibly

Details

With the exception of action = goto, the document cursor moves to the closing snippet tag (i.e., "</snippet>") when using RStudio.

action

  • goto (RStudio-only): Editor cursor jumps to beginning of code region without execution

  • skip (RStudio-only): Editor jumps to end of code region without execution

  • parse: Contents of the code region are run through cat without execution

  • exec: Contents of the code region are parse and executed from the global environment

  • save: Contents of the code region are saved to the current working directory using the keywords contained in `...` ending in '.snippet'

See also

Other Chapter 3 - Workflow Management: make.snippet(), snippets_toc()