Reputation: 1780
I have a R package that generates a RMarkdown html report. The .Rmd file lives in the system library/package directory.
I would like to create a function htmlreport()
to save the html report to the specified output directory path.
In case output_path
is not specified the function should give the possibility to browse to the output folder.
After rendering I would also like to open the resulting html report.
I am no sure how to do this. It seems that the path to the output file is always relative to the .Rmd file. How can I achieve this?
htmlreport <- function(output_path = NULL){
f <- system.file("inst/rmd", "html_report.Rmd", package = "abc")
if (is.null(outputh_path)) {
output_path <- ?? "Choose output folder" ....??
}
rmarkdown::render(f, output_dir = output_path)
# and open the html report..?
}
Upvotes: 0
Views: 559
Reputation: 2174
output_dir
can be any path, not only relative to rmd file.
To select a folder, you can use function choose.dir()
in base R package utils
or function selectDirectory()
in rstudioapi
(which means that it will only work if function is launched from rstudio
)
To display the html file use function browseURL
from base R package utils
using url constructed with paste0("file://",<full path of your file using / separator>)
Upvotes: 1