This is a really small point, but it's important for something bigger that I'm creating.
When I run a .Rmd file within RStudio by pressing the "Knit Word" button, the Word file that is created opens automatically.
However, when I run the file using the render() function, the file is created but it does not open -- I have to navigate to the file location and open it manually.
How can I get the output file to open automatically using the render() function?
I still don't know how to open the file directly from render() but another option is to use the following, where "example.Rmd" is a .Rmd file:
render("example.Rmd")
system2("open","example.docx")
You cannot do it directly with the render
function. But you can easily open the document using e.g. browseURL
.
filepath <- "C:/test"
render(file.path(filepath, "test.Rmd"))
browseURL(file.path("file:/", filepath, "test.docx"))
I am using the params
option in my YAML and want users to be forced to choose the desired parameter. Therefore, I'm using the knit
option in my YAML so that I can specify to the file that I want it to ask users for parameter input. I also wanted the file to open automatically. I used the following code to:
Code sample
---
title: "Clean data"
subtitle: "Step 2 and 3"
output:
html_notebook:
theme: readable
highlight: tango
params:
Choose:
value: Step 2
choices:
- Step 2
- Step 3
input: select
multiple: no
knit: (function(inputFile, encoding) {
out_dir <- "";
rmarkdown::render(inputFile, params = "ask",
encoding = encoding,
output_file = file.path(dirname(inputFile),
out_dir, 'Clean data Step 2.html'));
browseURL(file.path(dirname(inputFile),
'Clean data Step 2.html')) })
---
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