Do not open RStudio internal browser after knitting

喜欢而已 提交于 2019-12-09 02:20:05

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/31697945/do-not-open-rstudio-internal-browser-after-knitting

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