Repository navigation
Pre-run examples in website manual #7955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| library(tools) | ||
| library(xml2) | ||
| library(data.table) | ||
|
|
||
| # Create reference directory | ||
| ref_dir = "site/reference" | ||
|
|
@@ -48,8 +49,23 @@ for (rd_file in rd_files) { | |
| out_file = file.path(ref_dir, paste0(info$name, ".html")) | ||
|
|
||
| temp_html = tempfile(fileext = ".html") | ||
| Rd2HTML(rd_file, out = temp_html, package = "data.table", Links = topic_links, Links2 = character()) | ||
| html_root = read_html(temp_html) | ||
| Rd2HTML(rd_file, out = temp_html, package = "data.table", Links = topic_links, Links2 = character(), Rhtml = TRUE) | ||
|
|
||
| # The <!--begin.rcode ... end.rcode--> blocks are unsafe to parse as HTML, as an --> inside R code would terminate the comment. | ||
| env = new.env() | ||
| html_text = readLines(temp_html) | ||
| begin.rcode = which(startsWith(html_text, "<!--begin.rcode")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I don't see this documented in The current
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These "rcode" blocks follow the I can adjust our script to use the exact patterns from |
||
| end.rcode = which(html_text == "end.rcode-->") | ||
| stopifnot(length(begin.rcode) == length(end.rcode), begin.rcode < end.rcode) | ||
| for (i in seq_along(begin.rcode)) { | ||
| text = html_text[begin.rcode[i]:end.rcode[i]] | ||
| text[1] = sub('^<!--begin[.]rcode(.*)', '```{r}\n#| \\1', text[1]) | ||
| text[length(text)] = '```' | ||
| html_text[begin.rcode[i]] = litedown::fuse(text = text, envir = env) | ||
| html_text[(begin.rcode[i]+1):end.rcode[i]] = "" | ||
| } | ||
|
|
||
| html_root = read_html(paste(html_text, collapse = '\n')) | ||
|
|
||
| if (!is.null(html_meta$lang)) | ||
| xml_attr(html_root, 'lang') = html_meta$lang | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.