I'm working on a presentation in RStudio using rmarkdown and revealjs template. Since it's a work in progress, I often knit the .Rmd file to see the changes.
The problem is, each time I press "Knit" button (or use a hotkey), an internal browser window pops up. I don't need it, really, because 1) it displays the presentation incorrectly and 2) I already have the .html file open in my system browser and I simply refresh the page.
Is there any way to suppress the default RStudio behaviour?
Ideally, I'd love to be able to knit and see the result in the system browser (with focus on it) in as few keypresses as possible. Right now, my solution is to source(render.R)
, which contains a call like
library(rmarkdown)
library(revealjs)
render("main.Rmd",
revealjs_presentation(theme="black", highlight="zenburn"),
encoding = "UTF-8")
Better than nothing, but still a bit tedious (set focus from editing to console, source, refresh page -- 3 actions). Any suggestions?
For an MWE, open [New File] -- [R Markdown...] and hit "Knit HTML" or Ctrl+Shift+K.
Better still, RStudio includes a “Knit” button that enables you to render an . Rmd and preview it using a single click or keyboard shortcut.
No Knit HTML button This means that RStudio doesn't understand your document is supposed to be an RMarkdown document, often because your file extension is . txt. To fix this, go to the Files tab (lower right corner, same pane as Plots and Help) and select the checkbox next to your document's name.
If a chunk works in R but not when you knit, it is almost always because you've changed a variable in your global working environment not using code in a chunk. Try restarting your R session and running each chunk sequentially to make sure all your variable values are up to date.
knit - You can knit the file. The rmarkdown package will call the knitr package. knitr will run each chunk of R code in the document and append the results of the code to the document next to the code chunk. This workflow saves time and facilitates reproducible reports.
RStudio keeps moving this feature around. Johnathan's answer was good for the prior version of RStudio that I was using. You could find it starting with Tools > Global Options and then if you are on 0.99.x, here:
I'm currently on 1.0.44 and now it's here:
In all fairness to RStudio, I think creating a new R Markdown option section and putting it here makes good sense.
To add a litte bit to the answer of Michael (on how to disable the internal window):
I am using only the following script by sourcing it to render the file and open the resulting html file in the browser in one step:
library(rmarkdown)
library(revealjs)
file.name <- "introduction"
path.to.file <- "vignettes/"
rmarkdown::render(file.path(path.to.file, paste0(file.name, ".Rmd")),
revealjs_presentation(theme="default", highlight="default"),
encoding = "UTF-8")
browseURL( file.path(path.to.file, paste0(file.name, ".html")))
Note: This script does also work within a package project of RStudio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With