The service will be shut down on April 1st. Please see this page for more information.

I. Getting Started with R

Primary Contact(s) Created Required Software Example Datafile
Rich Glor 7 March 2009 [WWW]R See Introduction

Introduction|I. Getting Started|II. Tree Basics|III. Loading Character Data|IV. Testing Phylogenetic Signal|V. Ancestral Reconstruction|VI. Testing Patterns

A. Installing R and Associated Packages for Phylogenetics

Begin by downloading and installing the basic R framework from [WWW] After you’ve done this, you’ll need to open R and install a number of phylogenetic-specific applications using R’s interactive installation function. Doing this will require that you’re logged onto the internet. We’re going to install four packagess: APE (Paradis 2004) and GEIGER (Harmon et al. 2007), Ade4, and Picante.

B. Basic (Non-Phylogenetic) Functions in R

The great thing about R is that many basic functions are already built in. I’m not going to review all of the basic R functions here, but I do want you to start getting an idea of how R works. There are lots of other places to find more detailed information about basic R functions (e.g., Ch. 2 of Paradis 2006).

Let’s begin with some basic math. If you type ‘8+1’ at the command prompt and hit return you should get the answer ‘9‘ from R. Try experimenting with some other basic mathematical functions like multiplication (*) and division (/).

Now let’s try to save the output of simple functions in R. This can be done with the ‘assign’ commands in R, which consist of a dash (-) plus a greater than (>) or less than sign (<). Together these characters can be used to make arrows (‘->’ or ‘<-‘) that point from the operation whose output you’d like to save (e.g., 8+1) to the place you’d like to save it (e.g., x). Try typing:

To confirm that the value ‘9’ has been saved to ‘x’, just type ‘x’ and hit return. The use of assignment functions will be among the most commonly used functions of R’s syntax, so you should get familiar with how to use them now.

C. Commenting in R

Before we go any further, there is one other basic command to know about R; the number sign (#) is used to indicate comments in R’s syntax. Those of you with programming experience will know that comments are an important part of any programming language and can be used to tell the language to formally ignore text that appears following the comment indicator. Thus, text appearing after a number sign is ignored by R. Try typing:

R should give you the same result as typing just ‘8+1’. Comments will become increasingly important as you learn to program in R because they allow you make notes to yourself and others that are embedded in your R scripts.

D. Getting Help in R

Every R package has help documentation. These help documents should be the first place you turn when you run into trouble. Learning how to use them should be one of the first things you do in R. I’ll warn you right now, R help documents can be difficult to interpret and, in many cases, won’t provide you with the help you’re looking for, but this is no excuse not to check them. As you gain experience with R, you’ll find the help functions increasingly useful.

Let’s say you’d like to get help with the command for reading trees into R. If you already know that this function is called read.tree there are two simple commands you can use to get help:



When you type either of these commands a new window should pop up with some basic information about the function in question.

If you don’t know the name of the command, but have some idea of what it’s intended to do, you can use the search available help documentation by typing:


Note that quotes are required in this case. Use of the help search function should give you a list of all the commands that contain the word tree in their name or in the associated help file.

If you want help figuring out what a particular package does, you can use the following line to get a list of all the functions offered by a particular package:


Before you ask anyone for help with R be sure you’ve checked the help file. Another good way to get help is to use Google to search through the many internet help forums. If you type ‘R read.tree’ into Google, for example, you should find a number of helpful documents and discussions.

Continue to part II: Tree Basics
This is a Wiki Spot wiki. Wiki Spot is a 501(c)3 non-profit organization that helps communities collaborate via wikis.