[英]Is it possible to knit an R Markdown file only to a preview window/pane in RStudio without saving an html file?
I would like to keep the base folder of my R Markdown project tree as uncluttered as possible and still use the Knit button in RStudio to see some results as an HTML output in the RStudio's preview window. I would like to keep the base folder of my R Markdown project tree as uncluttered as possible and still use the Knit button in RStudio to see some results as an HTML output in the RStudio's preview window. However, every time I knit, an HTML file is created to the base folder along my.Rmd files.
但是,每次编织时,都会在 my.Rmd 文件的基本文件夹中创建一个 HTML 文件。
My folder structure might look like this:我的文件夹结构可能如下所示:
If I've understood correctly - and do please correct me if I'm wrong - it is not very straightforward to output the HTML files to an upstream folder (here:"results" folder) from an R Markdown file by pressing the Knit button, so I would be willing to: If I've understood correctly - and do please correct me if I'm wrong - it is not very straightforward to output the HTML files to an upstream folder (here:"results" folder) from an R Markdown file by pressing the Knit button ,所以我愿意:
So, if there is no easy way of directing the HTML files to the "results" folder, can I prevent the creation of HTML files altogether and only preview the results in the preview window?因此,如果没有简单的方法将 HTML 文件定向到“结果”文件夹,我可以完全阻止 HTML 文件的创建,并且只在预览 window 中预览结果吗?
I don't know of a way to attach this to the knit
button, but you could write a function that does this:我不知道将其附加到
knit
按钮的方法,但您可以编写一个 function 来执行此操作:
rmarkdown::render()
with the output_dir
argument set the way you want.rmarkdown::render()
并按照您想要的方式output_dir
参数。 You can attach this function to a keyboard shortcut in RStudio using these instructions .您可以使用这些说明将此 function 附加到 RStudio 中的键盘快捷键。
Here's a simple version of the function:这是 function 的简单版本:
knit2 <- function() {
filename <- rstudioapi::getSourceEditorContext()$path
output_dir <- file.path(dirname(filename), "results")
result <- rmarkdown::render(filename, output_dir = output_dir)
getOption("viewer")(result)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.