How to open a local html file from R in an operating system independent way?

You might find my open.file.in.OS function useful, sources can be found here.

A short summary about what this function does:

  1. Check platform
  2. Based on platform, call:
    • shell.exec on Windows
    • open with system on Mac
    • and xdg-open with system on other Unix-like operating system
  3. Uses shQuote on the privided file

Update: See now the openFileInOS in the pander package.

library(pander)
openFileInOS("d:/del/dt/a.html")

References: this function is a forked version of David Hajage's convert function can be found here.


I just wanted to pull the answer given by @daroczig out of the comments and into an answer. If @darcozig wants to post this as a separate answer, I'll delete this copy.

openHTML <- function(x) browseURL(paste0('file://', file.path(getwd(), x)))

Tags:

R