Here are the examples of the r api knitr-current_input taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
19
File: csf.R, author: grssnbchr, license: MIT License
csf < - function() {
cmdArgs = commandArgs(trailingOnly = FALSE)
needle = "--file="
match = grep(needle, cmdArgs)
if (length(match) > 0) {
return(dirname(normalizePath(sub(needle, "", cmdArgs[match]))))
}
else {
ls_vars = ls(sys.frames()[[1]])
if ("fileName" %in% ls_vars) {
return(dirname(normalizePath(sys.frames()[[1]]$fileName)))
}
else {
if (!is.null(sys.frames()[[1]]$ofile)) {
return(dirname(normalizePath(sys.frames()[[1]]$ofile)))
}
else {
if (requireNamespace("knitr") && !is.null(knitr::current_input())) {
return(dirname(knitr::current_input()))
}
else {
if (nchar(rstudioapi::getActiveDocumentContext()$path) >
0) {
return(dirname(normalizePath(rstudioapi::getActiveDocumentContext()$path)))
}
else {
return(getwd())
}
}
}
}
}
}
19
File: paths.r, author: klmr, license: MIT License
knitr_path = function(...) {
if (!"knitr" %in% loadedNamespaces())
return(NULL)
knitr_input = suppressWarnings(knitr::current_input(dir = TRUE))
if (!is.null(knitr_input))
dirname(knitr_input)
}
19
File: ocnms_render_rmd.R, author: marinebon, license: MIT License
ocnms_get_modal_info < - function(rmd = knitr::current_input()) {
modal_id < - basename(fs::path_ext_remove(rmd))
row < - ocnms_get_sheet(sheets_tab = "pages") %>% dplyr::filter(svg ==
modal_id)
if (nrow(row) == 0)
stop("Need link in Master_OCNMS_infographic_content:modals Google Sheet!")
icons_html = NULL
if (!is.na(row$info_link)) {
icons_html = htmltools::a(shiny::icon("info-circle"),
href = row$info_link, target = "_blank")
}
if (!is.na(row$info_photo_link)) {
icons_html = htmltools::tagList(icons_html, htmltools::a(shiny::icon("camera"),
href = row$info_photo_link, target = "_blank"))
}
htmltools::div(htmltools::div(htmltools::tagList(icons_html),
style = "margin-top: 10px;margin-bottom: 10px; margin-right: 10px; flex: 1;"),
htmltools::div(ifelse(!is.na(row$info_tagline), row$info_tagline,
""), style = "margin: 10px; font-style: italic; flex: 20; "),
style = "display: flex")
}
19
File: render_rmd.R, author: marinebon, license: MIT License
get_modal_info < - function(rmd = knitr::current_input(), info_modal_links_csv) {
modal_id < - basename(fs::path_ext_remove(rmd))
row < - readr::read_csv(info_modal_links_csv) %>% dplyr::filter(modal ==
modal_id)
if (nrow(row) == 0)
stop("Need link in cinms_content:info_modal_links Google Sheet!")
icons_html = NULL
if (!is.na(row$url_info)) {
icons_html = htmltools::a(shiny::icon("info-circle"),
href = row$url_info, target = "_blank")
}
if (!is.na(row$url_photo)) {
icons_html = htmltools::tagList(icons_html, htmltools::a(shiny::icon("camera"),
href = row$url_photo, target = "_blank"))
}
htmltools::div(htmltools::div(htmltools::tagList(icons_html),
style = "margin-top: 10px;margin-bottom: 10px; margin-right: 10px; flex: 1;"),
htmltools::div(ifelse(!is.na(row$tagline), row$tagline,
""), style = "margin: 10px; font-style: italic; flex: 20; "),
style = "display: flex")
}
19
File: vt_file.R, author: phuse-org, license: MIT License
vt_render_to < - function() {
output < - opts_knit$get("rmarkdown.pandoc.to")
if (is.null(output)) {
output < - tryCatch({
all_output_formats(knitr::current_input())[[1]]
}, error = function(e) {
NULL
})
}
if (is.null(output)) {
output < - "html"
}
return(output)
}