1

for a few weeks now I have been learning a minimal amount of R, rmd, and about knitR to construct a program in r that will compile a pdf containing particular images. Once finished, it will become part of a larger project involving the creation of dense write-ups for users.

I have been struggling with trying to change the "fields" if you will (I am not sure what to call them for a latex document) proactively. For example...

\graphicspath{ {figures\} }
\title{\textbf{Document name}}
\author{Me, My Professor, Collaborators}

The above code is compiled properly in to a PDF by either pressing the button above the coding window or by using the command knit2pdf(input.location, output.location) in an r file.

It would seem a latex document is a little different from an r file is that passing values between them is more difficult then between two r files.

Is it possible to make variables for each of the parameters in each of the expressions that I could change either through r, or through some method in latex?

A hypothetical and ideal solution that I have found does not work (or is not at all straight-forward) is:

\graphicspath{ {filepathVariable} }
\title{\textbf{nameVariable}}
\author{authorsVariable}

If it helps, here is the r code that compiles the PDF

library(knitr)
createpdf <- function(input.path, output.path){

  knit2pdf(input = input.path, output = output.path)

}
OakfordK
  • 11
  • 1
  • I'm not sure this is exactly what you're looking for, but the RStudio documentation on [Parameterized Reports](http://rmarkdown.rstudio.com/developer_parameterized_reports.html) might be of help. – eipi10 Nov 29 '15 at 00:58
  • If you define variables in the environment that calls `knit2pdf` you can use these variables in the RNW chunks. See [this anser](http://stackoverflow.com/a/34017805/2706569) (last bullet point) that I just wrote. Once you have for example a `authors` variable in the calling enironemnt, all you need to do is: `\author{\Sexpr{authors}}`. – CL. Dec 01 '15 at 10:21
  • Thank you, this is what I needed. The code was quite simple as I just did as you said. Added an `authors` variable in the R file that was rendering it, and in the latex document I evaluated the variable authors with `\author{\Sexpr{authors}}` – OakfordK Dec 03 '15 at 21:34

0 Answers0