2

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

DaveRGP
  • 1,430
  • 15
  • 34
  • 1
    RStudio currently checks for a literal call to `html_notebook` in the YAML header, and populates various bits of UI based on that. You might want to file a bug report / feature request at http://support.rstudio.com, requesting detection of custom outputs that delegate to `html_notebook()`. – Kevin Ushey Mar 31 '17 at 18:02
  • Thanks for the response. How did you discover this, out of curiosity? – DaveRGP Mar 31 '17 at 21:35
  • @KevinUshey I have opened this with RStudio as recommended: https://support.rstudio.com/hc/en-us/community/posts/115007125208-Can-a-custom-R-Notebook-inherit-the-features-of-an-R-Notebook – DaveRGP Apr 03 '17 at 15:31
  • 1
    @DaveRGP Kevin is a software engineer who works on RStudio. :-) – Jonathan Apr 03 '17 at 17:40
  • Wow, ace. I'll take that as gospel then! – DaveRGP Apr 03 '17 at 21:24
  • @Jonathan I've written up an answer for the sake of closing this off etc. Happy to take an answer from either of you two though. Will leave this open a few days in case you'd like to. – DaveRGP Apr 04 '17 at 12:33

1 Answers1

0

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.

DaveRGP
  • 1,430
  • 15
  • 34