tutorial: Convert R Markdown Files to DataCamp Light HTML Files
RMarkdownファイルをDataCamp Light HTML形式として扱う
- CRAN: http://cran.r-project.org/web/packages/tutorial/index.html
- GitHub: https://github.com/datacamp/tutorial
- Vignettes:
> library(tutorial)
バージョン: 0.4.3
関数名 | 概略 |
---|---|
build_example |
Create example .Rmd file in the current working directory |
go_interactive |
Set up your R Markdown document to use DataCamp light |
build_example
> build_example()
go_interactive
> go_interactive
function (greedy = TRUE, height = 300)
{
stopifnot(is.logical(greedy))
stopifnot(is.numeric(height))
default_source_hook <- knitr::knit_hooks$get("source")
default_document_hook <- knitr::knit_hooks$get("document")
blocks <- NULL
knitr::opts_hooks$set(eval = function(options) {
if (tut_active(options, greedy)) {
options$eval <- FALSE
}
options
})
knitr::knit_hooks$set(source = function(x, options) {
if (tut_active(options, greedy)) {
ex <- options[["ex"]]
if (is.null(ex))
ex <- options$label
if (!(ex %in% names(blocks))) {
key <- sprintf("dc_light_exercise_%s", ex)
blocks[[ex]] <<- list(height = NULL, els = list(language = tolower(options$engine)),
ex = ex, key = key)
}
else {
key <- NULL
}
type <- options[["type"]]
if (is.null(type))
type <- "sample-code"
blocks[[ex]]$els[[type]] <<- paste(x, collapse = "\n")
height <- options[["height"]]
if (!is.null(height)) {
blocks[[ex]]$height <<- height
}
return(key)
}
else {
default_source_hook(x, options)
}
}, document = function(x) {
if (length(blocks) > 0) {
for (block in blocks) {
if (!all(required_elements %in% names(block$els))) {
stop(sprintf("%s does not contain all required elements. You need %s",
block$ex, collapse(required_elements)))
}
if (!all(names(block$els) %in% allowed_elements)) {
stop(sprintf("%s contains elements that are not understood by %s.",
block$ex, project_alias))
}
html <- render_exercise(block, default_height = height)
x[x == sprintf("dc_light_exercise_%s", block$ex)] <- html
}
pre <- sprintf("<script src=\"https://cdn.datacamp.com/%s\"></script>\n",
cdn_path)
x <- c(pre, x)
}
return(default_document_hook(x))
})
}
<environment: namespace:tutorial>