Juan Lozano
Juan Lozano

Reputation: 667

How to Knit a Rmd file with R code to generate a word document

I have created an Rmd file and I know that if I go to the tools bars and select "knit to word" it will generate a word document form me.

My question is how can I do this with R code without having to actually clicking on the "knit to word" option on the top tool bar?

I have this code but the word document it creates does not work

library(knitr)
knit("AutomationPricingReport.Rmd", "AutomationPricingReport.docx")

Upvotes: 6

Views: 8127

Answers (2)

Tung
Tung

Reputation: 28331

You can do something like this

rmarkdown::render("AutomationPricingReport.Rmd", 
                  output_file = "AutomationPricingReport.docx"
                 )

Upvotes: 6

dave-edison
dave-edison

Reputation: 3726

You can specify output: word_document in the YAML metadata at the top of the document.

Upvotes: 5

Related Questions