Description Usage Arguments Value Examples
Parse A roxygen-formatted block to into a block to be rendered as markdown
1 | parse_block(txt, type = "challenge", opts = "markdown='1'")
|
txt |
a character vector of length 1 that represents a block of text |
type |
the type of block any other blocks will be nested in |
opts |
other options to add to the div tags defaults to markdown='1' |
the modified block with div tags assigned in the appropriate places
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # Simple example showing that the block can be parsed with knitr in its own
# environment
e <- new.env()
assign("h", list(ello = "hello", ere = "there"), env = e)
txt <- parse_block("
#' ## Hello Challenge
#'
#' Say hello
#'
#' @solution olleH Solution
#'
#' ```{r}
h$ello # variables in the current environment are evaluated
h$ere
getwd() # working directory is the current directory
#' ```
", type = "challenge", opts = "markdown='1' style='color:red'")
tmp <- tempfile(fileext = ".md")
knitr::knit(output = tmp, text = txt, envir = e)
if (interactive()) file.edit(tmp)
# Example of a more typical block
f <- system.file("extdata", "example-number-echo.R", package = "dovetail")
txt <- paste(readLines(f, encoding = "UTF-8"), collapse = "\n")
cat(txt)
ptxt <- parse_block(txt)
tmp <- tempfile(fileext = ".md")
knitr::knit(output = tmp, text = ptxt, encoding = "UTF-8", envir = parent.frame())
if (interactive()) file.edit(tmp)
# Example of a block with multiple solutions
f <- system.file("extdata", "example-multi-solution.txt", package = "dovetail")
txt <- paste(readLines(f, encoding = "UTF-8"), collapse = "\n")
cat(txt)
ptxt <- parse_block(txt)
tmp <- tempfile(fileext = ".md")
knitr::knit(output = tmp, text = ptxt, encoding = "UTF-8", envir = parent.frame())
if (interactive()) file.edit(tmp)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.