Skip to contents

Run snippet code

Usage

update_local_snippet(force = TRUE)

load_snippet(topic, local = TRUE)

Arguments

force

whether to force updating the snippets; default is true

topic

snippet topic

local

whether to use local snippets first before requesting online repository

Value

`load_snippet` returns snippet as a function, others return nothing

Examples


if(!is_on_cran()) {

  update_local_snippet()
  snippet <- load_snippet("dummy-snippet")

  # Read snippet documentation
  print(snippet)

  # Run snippet as a function
  snippet("this is an input")
}
#> NOT_CRAN is TRUE/true (not on CRAN)
#> <RAVE code snippet: [dummy-snippet]>
#> Snippet path: /Users/runner/Library/Caches/org.R-project.R/R/raveio/rave-gists-main/dummy-snippet.R
#>   @author Zhengjia Wang
#>   @date Feb 08, 2023
#>   @license Apache-2.0
#>     
#>   @title This file is used to demonstrate how rave-snippet works
#>     
#>     A RAVE code snippet contains three sections:
#>       * documentation section,
#>       * variable section,
#>       * code section.
#>     
#>     This documentation is located at `documentation section`, starting with two
#>     characters `#'`. The section ends with `#' END OF DOC`. The documentation
#>     section describes what the code snippets do, and what are
#>     the inputs and outputs, and possibly with examples. To understand what
#>     inputs are, look for keywords `@param`, for example:
#>     
#>   @param my_input defines an input argument `my_input`, followed by
#>     its explanation
#>     
#>     
#>     The variable section starts right after `#' END OF DOC`. They are usually
#>     commented for a reason (see 'How to use snippets' below). You can download
#>     and un-comment these lines and run snippets as standalone scripts.
#>     
#>     The last section is code section, usually you don't have to change the magic
#>     there unless you know what you are doing.
#>     
#>   @section How to use rave-snippets:
#>     
#>     Scenario 1: You can download the script to your local disk, from there
#>     un-comment the *variable section*, set variable as required, and run the
#>     whole script using `ctrl/command+shift+enter` (or `command+enter` to run
#>     line by line)
#>     
#>     Scenario 2: You can use `rave` built-in functions to load the snippet:
#>     
#>         topic <- "dummy-snippet"   # <- this should be the snippet name
#>         snippet <- raveio::load_snippet(topic); snippet
#>         snippet(param1 = ..., param2 = ...)
#>     
#> 
#>   @usage: snippet(my_input, ...)
#> this is an input