How to open a local html file from R in an operating system independent way?
For demonstration purposes, assume that the file is called test.html
and is in the working directory.
system('gnome-open test.html')
browseURL(paste('file://', getwd(),'test.html', sep='/'))
You might find my open.file.in.OS
function useful, sources can be found here.
A short summary about what this function does:
shell.exec
on Windowsopen
with system
on Macxdg-open
with system
on other Unix-like operating systemshQuote
on the privided fileUpdate: 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)))
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