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')
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)
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.
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