utils::browseURL removes the query string with file:// urls?

Viewed 159

Within R, I'm trying to load a local .html file in a browser and pass a query string to it, which will then be read by javascript. I'm trying to use utils::browseURL for this. When I run this code in R:

utils::browseURL("https://rstudio.org?a=1")

it properly opens a browser to Rstudio's website, with the query string attached. However, when I run this code:

tf = tempfile(fileext = ".html")
cat("<html><head></head><body>hi</body></html>",file = tf)
url = paste0("file://", tf, "?a=1")
utils::browseURL(url)

it opens up the file in the browser, but without the query string. I would expect the "?a=1" to be appended, as with the Rstudio URL, but it is not.

How can I open a local .html file with a query string?

Session info below:

R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.2

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
[1] compiler_3.5.0  tools_3.5.0     packrat_0.4.9-3
1 Answers

I don't think it is possible. The problem here is that you can not have a ? in file path. And also query string is part of HTTP protocol so when dealing with local files the query strings are not enabled.

Related