Jeromy Anglim's Blog: Psychology and Statistics


Tuesday, November 23, 2010

makefiles for Sweave, R and LaTeX using Eclipse on Windows

This post provides a brief introduction to make and makefiles. In particular it describes how to set up make on Windows with an emphasis on using make in Eclipse on projects involving R, Sweave, and LaTeX.

Overview

make is software that uses makefiles to build projects. make has many benefits.

  • One click build
  • Reliable build (always build derived files that need to be built; i.e., ensure build is up to date)
  • Fast build (i.e., don't build things that don't need to be built)
  • Clean up a project

make has won the ACM Software System Award. It shares this honour with two of my other favourite tools: TeX and S.

make has also encouraged me to think more about dependencies, one-click builds, and project file structures. Specifically, I use make in conjunction with R, Sweave, LaTeX, and other command line tools to build reproducible research output. I'll post some examples in the near future.

Installation on Windows

  • Option 1: Install Cygwin
  • Option 2: Install Rtools and add Rtools to the Windows path (installation can do this for you);

In order to run Sweave on the command line on Windows using: R CMD Sweave foo.Rnw:

  1. Add R binaries to the Windows Path (e.g., C:\Program Files\R\R-2.11.1\bin; see here for instructions)
  2. Have Rtools installed

Introduction to R has more information about running R at the command line.

Running makefiles in Eclipse

I use Eclipse to edit R and Sweave files. To configure make in Eclipse:

  • Run - External Tools - External Tools Configurations
  • New
    • Name: make
    • Location: location of make file; e.g., C:\Program Files\GnuWin32\bin\make.exe
    • Working Directory: ${Project_loc}

Thus, with a makefile in the root directory of a project, Run - External Tools - Make runs the makefile.

Also note:

  • Whenever a directory is added to the Windows Path, Eclipse needs to be restarted for this to take effect. Sometimes it seems that Windows itself has to be restarted.
  • Editing makefiles in Eclipse requires the use of tabs. The following setting enables tabs instead of space substitution (Window - Preferences - General - Editors - Text Editors - Insert Space for Tables (uncheck)); or edit the makefile in another text editor such as notepad.
  • For LaTeX I have MikTeX installed; this should be on the Windows path

Resources for Getting Started with makefiles for Sweave

2 comments:

  1. Does anyone know how to integrate texmakerx and sweave on Windows? I mean, to run .rnw files directly from texmakerx and get a pdf or dvi file.

    Thank you in advance,
    Sebastian

    ReplyDelete
  2. @Seba I've never used it. Perhaps try asking on tex.stackexchange.com

    ReplyDelete