latexr: efficient compilation of dynamic reports integrating LaTeX and R

I have been working on the ideas and scripts introduced in this previous post. The result is a new set of scripts packaged in this latexR.tar.gz file.

The main enhancements are the following:

  • An environment can be assigned to each chunk, see ?environment in R. Dependencies are established only across those variables that are evaluated in the same environment. In this way, the names of variables can be reused without generating false dependencies. For example, two chunks may use the same variable named x, but both chunks may actually be independent of each other. This avoid having to come up with new names, such as x2, and remember all of them.
  • The R function all.vars is now used. This facilitates the detection of the variables created and used by each chunk, which is in turn used to determine dependencies across files.
  • Before, the output was placed after the whole R input chunk. When the chunk prints the value of more than one object, it may not be clear what each output refers to in the code chunk. Now, output is arranged by default in between input code in the same order as it would be printed on the console.

These are the arguments that can be passed to the new command latexr:

  • make: generate/update and run the Makefile. The following values can be passed to it:

    • doc=x, the name of the file without extension (assumed '.rnw'),
    • Rdir=x, the name of the directory where the R chunks will be stored,
    • figDir=x, the name of the directory where the figures will be placed.
  • clean: delete LaTeX and R auxiliary and output files.
  • reload: reload .Rprofile (if any).
  • clear: delete .R and .Rout files evaluated in a given environment.
  • help: brief description of available arguments and options.

A sample rnw file and output is available here. The output pdf file is built by means of the following command (after installling latexr): latexr make.

At the moment the documentation is a bit short. Don't hesitate to contact me if you need some clarifications on the usage of these scripts.

This entry was posted in LaTeX, literate programming, R and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *