In r studio, how does the IDE treat notebooks with the 'preview' button

最后都变了- 提交于 2019-12-24 10:54:01

问题


I am building a custom formatted notebook using some css and html. As recommended this is implemented using a wrapper function around an rmarkdown function.

quarterly_report <- function(toc = TRUE) {

  # get the locations of resource files located within the package
  css <- system.file("reports/styles.css", package = "mypackage")
  header <- system.file("reports/quarterly/header.html", package = "mypackage")

  # call the base html_document function
  rmarkdown::html_notebook(toc = toc,
                           fig_width = 6.5,
                           fig_height = 4,
                           theme = NULL,
                           css = css,
                           includes = includes(before_body = header))
}

However, when I run this using the YAML in the suggested manner:

---
title: "Habits"
output:
  mypackage::quarterly_report:
    toc: true
---

It will run, but there is no option to 'preview' the notebook using the buttons on the IDE, only knit.

I therefore have 2 questions:

  1. What do I miss from not having this functionality?
  2. How can I replicate the contextual RStudio behaviour where it knows it is notebook?

UPDATE: After some more testing IRL it appears that the 'preview' button might cache/precompile material. I am finding that for bigger processing jobs the time between clicking the button and obtaining output is longer for 'knit' than it is for 'preview', with rmarkdown giving an output in the 'rmarkdown' tab of the console pane


回答1:


After moving this to the rstudio support page, a partial solution has been given.

---
title: "Report title"
output:
 html_notebook: default
 mypackage::quarterly_report: default
---

The above YAML header will give the option to compile as a standard, non-custom RNotebook, and apply the 'custom' formatting, and output in html_document style with the second argument, These can be flicked through at will via the drop down knit button in RSutdio IDE.



来源:https://stackoverflow.com/questions/43115852/in-r-studio-how-does-the-ide-treat-notebooks-with-the-preview-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!