Installing and Running R and MATLAB
1.1 Obtaining and installing
R can be downloaded for free from The R Project Web site at http://www.r-project.org.
Follow the link to CRAN (Comprehensive R Archive Network) to download R. You must
ﬁrst choose a CRAN mirror, i.e., one of the many Web sites around the world that keep
copies of the R software. It is probably best to choose one that is geographically close to
Once you have chosen a mirror, you can choose which operating system (Linux, Mac
OS-X, or Windows) you use. Depending on your operating system, you may then have
further choices to make, such a s which dis tribution of Linux or which version of OS-X you
use. Note that the source code for R is also fre ely available for download from the same site.
When you actually run R on Windows or Mac OS-X, you will see a graphical user in-
terface like the one shown in Figure 1.1. T he interface primarily consists of the R Console
or Command window, where you can interactively type commands for R to interpret. The
standard comma nd pr ompt in R is “>,” which means R is waiting for you to type a com-
mand. You c an try it out with some simple computations; for example, type 7*8 (and then
press Enter) to do a simple multiplication, or sqrt(exp(3)) to compute
. When you
run R on Linux in a terminal, you just get the command prompt, without the various menus
in the interface for OS-X and Windows.
You may wis h to use a much more compr ehensive, friendlier interface, especially if you
are coming to R from MATLAB. A very popular integrated development environment for
R, which has many of the same useful feature’s as MATLAB’s interface, is called RStudio;
it is available from http://www.rstudio.com. RStudio’s interface is shown in Figure 1.2.
If you are trying to ease your transition from MATLAB to R, you may seriously want to
consider installing and loading the pracma package, as it implements many functions which
behave nea rly equivalently with MATLAB routines; see Section 13.9 fo r information about
installing and loading packages.
MATLAB is available from The MathWorks, Inc . (http://www.mathworks.com). Pric-
ing and licensing information is available under their “Products & Services” link. There is a
very inexpensive option for students, and also special pricing for home and educational use.
It is also possible to obtain a trial version of the software. When you purchase MATLAB,
you will receive information for how to download and activate your copy.
MATLAB is available for all three popular operating sy stems (Linux, Mac OS-X, and
When you run MATLAB, you will see a graphical user interface like the one shown in
Figure 1.3. The large region in the middle of the us er interface is the Command Window,
2 R and MATLAB
FIGURE 1 .1
The R graphical user interface in Mac OS-X.
Installing and Running R and MATLAB 3
FIGURE 1 .2
The RStudio graphical user interface in Ma c OS-X.
4 R and MATLAB
FIGURE 1 .3
The MATLAB graphical user interface in Mac OS-X.
where you can interactively type commands fo r MATLAB to interpret. The standard com-
mand prompt in MATLAB is “>>,” which means MATLAB is waiting for you to type a
command. You can try it out with some simple computations; for example, type 7*8 (and
then press Enter) to do a simple multiplication, or sqrt(exp(3)) to compute
There are also many other things visible in the user interface. These include:
• A ﬁle browser, listing the ﬁles in a given directory.
• More information about a selected ﬁle.
• The MATLAB workspace viewer, showing the variables that are currently deﬁned.
1.2 Commands for getting help
Both platforms oﬀer extensive built-in documentation. Depending on your operating sys-
tem, documentation may be available from menus or other items in the user interface.
Example commands are shown below, demonstrating how to access the various built-in
documentation systems from the command window.
help('eigen') Display documentation for the eigen function.