Getting Started with R in Stat 341

Download R

Here are the steps to download R to your own personal computer.
  1. Open an internet browser program, such as Internet Explorer and go to the website address http://www.r-project.org

  2. On the left hand side of the page, under Download, click on the link CRAN.

  3. Scroll down the page until you get to the list of sites for the USA. Click on the link at Iowa State University.
      Here is a short cut: http://streaming.stat.iastate.edu/CRAN/

  4. In the top box, click on the link that corresponds to your computer and operating system. The remaining directions will be written for downloading R to a computer running Windows 95 or later.

    If you have a MAC or are running Linux, please follow the directions on the CRAN website to download the program.

  5. Click on the link Windows (95 or later).

  6. Then click on the link base.

  7. To complete the download, click on the link R-2.7.1-win32.exe. You will be asked if you want to open this file or save it to a disk. You should save this file to your desktop.

  8. After the file has downloaded, double-click on the R-2.7.1-win32.exe icon on your desktop and follow the instructions to install the program.

  9. The installation should place a shortcut to run R on your desktop. To run R, you simply need to double-click on the shortcut.

Here are the steps to save your output from R.

  1. To save your work from the R console: Click on File and Save to File. Choose a location to save this text file to on your computer and a name for the file. If you use the name myoutput, then the computer will save it as myoutput.txt. You can open your saved text file in MS Word or any other word processing program. You can edit this document and use it as part of your homework assignment.

  2. To save your data files: From the command prompt, type save.image(".RData"). This saves your data objects in a file called .RData. You can use other names if you wish, such as save.image("mydata.RData"). The extension .RData is recognized by the R program.

    You can return to the data image when you restart R. Option 1: Simply double click on an icon R for a file with the .RData extension. The R program should start with the data loaded into it. Option 2: If you double click on the R program icon from your desktop, it will automatically load the .RData file. Option 3: Double click on the R icon from your desktop and your data do not load, then under File select "Load workspace" and open the .RData file that you want.

  3. Exiting R: You can quit R by typing q() at the prompt or selecting "Exit" under File. You will be asked whether you want to save the image of the database. If you answer Yes, it saves the latest version as .RData. If you answer No and you have not saved the data files, then the data will be gone. Typically I type Yes even if I have saved the data under an original name. Note: saving the data image (.RData) does not save the output and text of your work in the R console. If you want to save the work on the R consule you must save it separately; see the first step above.

A note about using public computers and saving work

If you are using R on a public computer, then it is likely that periodically the computer will erase user-created files, including your R files left behind. Therefore, if you want to save any work, it is important to move the files to a computer account location that will not be erased.

It is possible to attach R files (.RData, mydata.RData, myoutput.txt, and graphs) to emails. One option if you have no other way to save work, therefore, is to email the files to yourself and save them later on another computer. For example, once you save a .RData file on a computer, you can double click on the .RData icon and it will start the R program, provided of course that R is installed on the new computer. When on a university computer, another option is to save any files to your Afs disk space. Your disk space can be found under the My Computer heading.

Here are the steps to print output or graphs from R.

  1. Make sure your computer has a connection to a printer.
  2. Make the window you wish to print the active window.
  3. Click on File and Print.
  4. Follow the directions to print the window.

Here are the steps to save a graph in R.

  1. Make the graph window the active window.
  2. Click on File and Save As.
  3. Select a format to save the file to. You will probably want to use PDF, Bmp, or Jpeg.
  4. Select a name for the file and location on your computer.
  5. Click Save.