R - Introduction


R is an interpreted programming language and software environment for statistical analysis, graphics representation and reporting. R also allows integration with the procedures written in the C, C++, .Net, Python or FORTRAN languages for efficiency. R is named so after the creators Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team.

R-Studio is most commonly used for development. It provides features to run commands as well as scripts. You can install R and R-Studio from their website.

R Command Prompt


Once you have R environment setup, then it’s easy to start your R command prompt by just typing the following command at your command prompt:

> myString <- "Hello, World!"
> print ( myString)
[1] "Hello, World!"

Here first statement defines a string variable myString, where we assign a string "Hello, World!" and then next statement print() is being used to print the value stored in variable myString.

R Script File


Usually, you will do your programming by writing your programs in script files and then you execute those scripts at your command prompt with the help of R interpreter called Rscript. So let's start with writing following code in a text file called test.R

# Hello World
myString <- "Hello, World!"
print ( myString)

You can save the above code in a file helloWorld.R and execute it at the command prompt as given below. You can also do that within the R-Studio if you want to avoid the hassles of setting up the path.

$ Rscript test.R 
[1] "Hello, World!"