Rmarkdown - How to create a . pdf with a different name than . Rmd?

Asked

Viewed 101 times

4

I created a script in . Rmd that will be played for different years. So I would like to be able to change the name of the generated . pdf.

As it is: Report File.Rmd generates Report.pdf

How I would like: Relatório.Rmd gera Relatorio_2017.pdf

---
title: "Titulo"
subtitle: "Subtitulo - 2017"
author: "Eu"
date: "`r format(Sys.time(), '%d %B, %Y')`"

output:
  pdf_document: 
    toc: true
    number_sections: true
    latex_engine: xelatex

header-includes:
  - \usepackage[portuges]{babel}
  - \usepackage{setspace}  \singlespacing
indent: false #
mainfont: Arial
monofont: Arial
fontsize: 12pt
geometry: "left=3cm,right=3cm,top=2cm,bottom=2cm"

abstract: \singlespacing  Resumo aqui

---

  • 3

    Try to run the document with rmarkdown::render() or knitr::knit() then you can pass the name.

  • Thank you! I’ll try !

1 answer

5


You can use the function render for this. Remembering that this function cannot stay inside the file .rmd, she has to be inside a file .R.

Code

render(input = "nomeDoSeuArquivo.Rmd",
       output_file = "nomeDesejado.pdf",
       output_format = pdf_document,
       knit_root_dir = getwd(),
       encoding = "UTF-8",
       quiet = TRUE)

Another option is to use the function file.rename.

Code:

file.rename(from = "nomeDoSeuArquivo.pdf",
            to = paste0(nomeDesejado - ", "ano", ".pdf"))
  • 1

    Thanks! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.