By default, the knit/Sweave command will generate a tex file with the same name as the .Rnw file. I want to give it and the subsequent pdf file a different name is it possible?
Asked
Active
Viewed 2,289 times
5
-
10You have an `output` argument in `knit` or `knit2pdf`. – Victorp Feb 19 '14 at 14:46
-
Crap! I don't know how I missed that. Is there a way to append a variable name from the knitting file (in a R code chunk) to the filename? I ask because I am already generating an ID in the knit, I don't want to generate another random number for the file name. – Avinash Feb 20 '14 at 05:43
-
The answer is yes definitely, but depends on how you generate the id in .Rnw. You will get answer if you show a sample. – kohske Feb 20 '14 at 06:29
-
Thanks. I figured it out. – Avinash Feb 20 '14 at 06:33
-
1Where can I set this argument? Background: I'm compiling rnw files with RStudio by clicking on the "Compile PDF" button. What I want is that each time I create a pdf file, the current date get appended to the pdf filename and thus formely generated pdfs do not get overwritten. – moabit21 Feb 26 '14 at 10:52
-
@moabit21 Instead of clicking "Compile PDF" use the function knit2pdf from knitr. In that you can pass an argument output, so say my Rnw file is called "test.Rnw" I would call knit2pdf(test.Rnw,output=paste0("test",Sys.time())) – Avinash Dec 18 '14 at 07:14
1 Answers
3
In the header of an .Rmd
file, you can specify a file name:
---
title: "My title"
output:
pdf_document:
pandoc_args: [
"--output=Custom_name.pdf"
]
---
For .Rnw
files you can directly call the function knitr::knit2pdf
:
knit2pdf(input.Rnw, output="Custom_name.pdf")

mrub
- 501
- 2
- 12
- 30
-
1+1 for `pandoc_args`, but this is only valid for RMD files. As the question is about RNW, you maybe want to add the suggestion from the comments (`knit2pdf`, argument `output`) to your answer. – CL. Jan 04 '16 at 09:14