rstats-wtf / wtf-2019-rsc

What They Forgot to Teach You About R, 2019 January 15/16 @ rstudio::conf
https://rstd.io/wtf-2019-rsc
41 stars 76 forks source link

Opening HTML or PDF in RStudio viewer pane #6

Open DSHerzberg opened 5 years ago

DSHerzberg commented 5 years ago

Is there a way to do this without rendering a .rmd? I found this code but couldn't figure out how to apply it:

tempDir <- tempfile() dir.create(tempDir) htmlFile <- file.path(tempDir, "index.html") # (code to write some content to the file) viewer <- getOption("viewer") viewer(htmlFile)

jennybc commented 5 years ago

The main constraint, for security reasons, is that RStudio's Viewer will only open files below the session temp directory.

But maybe @kevinushey can weigh in to correct or refine this.

kevinushey commented 5 years ago

That is indeed correct.

DSHerzberg commented 5 years ago

Does this mean that it can't be done?

gaborcsardi commented 5 years ago

You can do it, but you need to copy the file(s) into tempdir() and then open them from there with the function returned by getOption("viewer").