I find it easiest to use RStudio. You can also paste the code in a normal R console or let R run a source file. However these approaches are a bit less fail-safe.

Using RStudio

Download and install RStudio.
Open RStudio and do this:

  1. Click on the menu: File -> New -> R Script
  2. Paste the code in the new source code area
  3. Click the "Source" button above the code area:

You can also use the console in RStudio. If you click "Run" instead of "Source" user input might not work properly.

You can use the R documentation like this: help(function.name).

Using the R console

Running the r program on the command line or elsewhere will start the console. You can paste your code there.

Problems with this approach

This will generally work if you use source("filename.r") to run your code. If you paste the code some of it might be read as user input.

Running a source file with R

You can run a source file like this: r -f filename.r.
R also provides a lot of other command line arguments.

Problems with this approach

I have not managed to get user input to work here.