2011年3月24日星期四

Setting up R and LATEX

Setting up R and LATEX

http://statmath.wu.ac.at/software/R/qfin/

Yilmaz Ceylan

Stefan Theußl

February 10, 2011

Contents

[PDF version of this manual]

1 Introduction

This article explains how to set up R and LATEX on various operating systems. We provide a set of instructions for the three major desktop operating systems Windows, Mac OS X, and Linux in Sections 2, 3, and 4, respectively. Section 5 includes references to related articles and further resources. For more information about R please visit the website of the R project at http://www.r-project.org/. Further questions not covered by this article and feedback may be sent to statmath-qfin_AT_wu.ac.at.

2 Windows

If you are using Windows you should follow the steps below in order to successfully setup a basic R development environment.

  1. Install the current version of R (available from http://CRAN.R-project.org/bin/windows/base/).
  2. Set up a working LATEX environment (e.g., MiKTEX http://miktex.org/; preferably installing all available packages).
  3. Install the R for Windows toolchain (known as R-Tools, available from http://www.murdoch-sutherland.com/Rtools/).
  4. Update your environment variables.

LATEX Environment

The most popular option for setting up a LATEX environment on Windows is installing the MiKTEX distribution. We recommend to download the net installer from http://miktex.org/, execute it, and install MiKTEX including all packages (full installation).

Installing the R for Windows Toolchain

R-Tools includes various software needed for successfully building R packages (typically packages containing C or FORTRAN source code). It provides Windows with a set of compilers and various other tools and libraries.

Not included in the R-Tools package is the Microsoft htmlhelp compiler. It is used to produce compiled HTML sites of R help pages. You may download the software from http://msdn.microsoft.com/en-us/library/ms669985(VS.85).aspx.

Updating Environment Variables

Presumably the most important step is to update the PATH environment variable.

For doing so go to: Start Settings Control Panel System Advanced.
Search for the PATH variable and change it appropriately. The paths to the ‘bin’ directories of the following software have to be included (if they were not included automatically):

  • R-Tools
  • MiKTEX
  • htmlhelp
  • R

Note that the order of the entries is important, thus “copy and paste” the paths in the order seen above. Separate them by semicolon. Do not delete other entries, Windows may need them.

Links, from where you can download suitable text editors:

3 MAC OS X

In order to successfully setup a basic development environment for R- related projects under MAC OS X you need to follow these four steps:

  1. Install the current version of R (available from http://CRAN.R-project.org/bin/macosx/ ).
  2. Install a LATEX environment (e.g. TeXShop, teTeX).
  3. Install XCode.
  4. Install the GNU Fortran compiler (gfortran).

LATEX environment

A readily usable environment for typesetting scientific articles with LATEX is provided with the MacTEX distribution available from http://www.tug.org/mactex/2009/. This distribution also includes a text editor named TeXShop.

XCode

Compilers are needed for installing R packages containing source code typically written in C or FORTRAN. A set of C compilers for Mac OS X is provided in XCode the basic development tools for Mac OS X installable either from the DVD containing the operating system that came with your Mac or, after downloading the latest version from the Apple Developer website at http://developer.apple.com/technology/xcode.html.

GNU FORTRAN compiler

Unfortunately, the compiler gfortran is not included in XCode. Luckily, since R version 2.5.0 the compiler is installed with the R Mac OS X installer (see Step 1: Installing the current version of R). Nevertheless, if you experience problems setting up the compiler you may install it manually using the packages provided at http://r.research.att.com/tools/.

4 Linux

As we cannot provide a complete set of instructions for every Linux distribution we concentrate on Debian-based distributions in this article. The most prominent of such Debian-based Linux distributions is called Ubuntu (http://www.ubuntu.com). Nevertheless, the instructions provided in this section should usually work on any Debian-based system.

In order to successfully setup a basic development environment for R under Debian you need to follow these three steps:

  1. Install the current version of R (r-base and r-recommended packages).
  2. Install a LATEX environment (e.g., TeX Live available by installing the texlive-full package).
  3. Install compilers and other development packages.

Installing R

R is provided in binary form as Debian packages called r-base. It can be installed either by using the synaptic package manager or by issuing the following command on the command prompt:

sudo aptitude install r-base r-recommended

For installing more recent versions of R please follow the steps provided in please visit the R on Debian or R on Ubuntu websites http://www.ubuntu.com.

LATEX environment

A readily usable environment for typesetting scientific articles with LATEX is provided with the TeX Live distribution available from www.tug.org/textlive/. Luckily, one can install the complete distribution with the texlive-full package very easily. It can be installed either using the synaptic package manager or by issuing the following command:

sudo aptitude install texlive-full

Compilers and Other Tools

Typically, compilers and other development tools are needed in a reasonable development environment. Those tools are made available on Debian-based system simply by installing the r-base-dev package. It can be installed either using the synaptic package manager or by issuing the following command:

sudo aptitude install r-base-dev

5 Further Information

More information about the topic can be retrieved from the following references.

6 Frequently Asked Questions

  1. Windows (MiKTEX):
    1. How to make MiKTEX recognize ‘Sweave.sty’?

      Answer: Go to your R Installation directory, i.e. the directory where R has been installed to. We call this directory ‘RHOME’. Search for the LATEX style sheet called ‘Sweave.sty’. Typically it is located in the folder ‘<RHOME>\share\texmf\’. Copy the content of this folder to the ‘Sweave’ folder in your “personal” LATEX library. The location of your LATEX library can be seen by going to Start All Programs MiKTeX <Version>Maintenance Settings.

      Go to the Roots tab, and mark the “Show MiKTeX-maintained root directories”. Look at the Description where it says “UserInstall,UserConfig”. The coresponding Path points to the location. Usually it is in ‘<RHOME>\Application Data\MiKTeX\<Version>\tex\latex\’, (<Version> has to be replaced with the installed MiKTEX version), if you don’t have the ‘latex’ and/or the ‘Sweave’ folder, please create it.

    2. How to install further LATEX packages?

      Answer: Go to Start All Programs MiKTeX<Version> Maintenance(Admin) Package Manager(Admin).

      Search for the package you need, then right click on the package name and click the Install.

    3. MikTEX offers downloading missing packages but fails.

      Answer: Note that you have to be able to write to the system library of MiKTEX. Typically this can only be achieved when you login as an Administrator.

7 Acknowledgment

An earlier version of this manual was written by Ksenia Fraczek.

没有评论:

发表评论