Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View markdown generated html in RStudio viewer

Tags:

r

r-markdown

I would like to see html file that is generated using markdown in RStudio viewer, but rstudio::viewer('test.html') opens my file in browser outside RStudio. Could you tell me how can I achieve this?

THIS example works but I don't know why my example doesn't work in that way.

test.html file it'a an complied example that we get when we choose new file -> R Markdown.

EDIT (according to Roman Luštrik comment)

library(knitr)
library(markdown)
f <- system.file("examples", "knitr-minimal.Rmd", package = "knitr")
knit(f)
markdownToHTML('knitr-minimal.md',output='knitr-minimal.html')
rstudio::viewer('knitr-minimal.html')
like image 620
Maciej Avatar asked Apr 09 '14 06:04

Maciej


2 Answers

The key is using tempfile(), as explained here. Whenever the html file is outside the session temp dir, Rstudio won't display it.

This, on the other hand, will work:

temp.f <- tempfile()
cat("Hello", file = temp.f)
rstudio::viewer(temp.f)

Edit

As was pointed out by @Sebastian Palma in his comment, the "rstudio" package has been replaced by "rstudioapi", so that the third line should now be:

rstudioapi::viewer(temp.f)
like image 146
Dominic Comtois Avatar answered Oct 30 '22 23:10

Dominic Comtois


On my version of RStudio (0.98.994), clicking on the small down arrow on the right side of the "knit HTML"button gives me the options "View in Pane" and "View in Window". Selecting the first instead of the second fixed it for me.

like image 45
thi_sanna Avatar answered Oct 30 '22 21:10

thi_sanna