Hello World in R Programming

Running your first R program is an exciting step in getting started with the R programming language. Here's a detailed guide on how to run your first R program:

Open RStudio

If you've installed RStudio, launch it from your applications or program list.

Create a New R Script

In RStudio, go to the top left corner and click on "File" > "New File" > "R Script." Alternatively, you can use the keyboard shortcut Ctrl + Shift + N (Windows/Linux) or Command + Shift + N (macOS).

Write Your Code

In the new script file, you can start writing your R code. For your first program, let's print a simple "Hello, World!" message to the console.

# This is a comment print("Hello, World!")

Lines starting with a "#" are comments and are ignored by R. Comments are used to provide explanations and context to your code.

Running Your Code

To execute your code in RStudio, you can select the lines you want to run and then click the "Run" button located at the top right corner of the script editor. Alternatively, you can use the keyboard shortcut Ctrl + Enter (Windows/Linux) or Command + Enter (macOS).

You will see the output of your code displayed in the console panel at the bottom left of the RStudio interface. In this case, you should see "Hello, World!" printed.

Hello, world!

Saving Your Script

After running your code successfully, it's a good practice to save your script. Click on "File" > "Save" and choose a location on your computer to save the script. Give it a meaningful name and use the ".R" extension (e.g., "my_first_program.R").

Using the Console Directly

You can also run individual commands directly in the console. Just type the command and press Enter to see the output. For example, typing 2 + 2 and pressing Enter will display the result "4" in the console.

Experiment and Explore

Now that you've successfully run your first R program, you can start exploring more R functions, data structures, and concepts. Try simple arithmetic operations, variable assignments, and basic data manipulations.

Learning Resources

As you progress, you can refer to R documentation, online tutorials, and courses to deepen your understanding and explore advanced topics such as data analysis, visualization, and statistical modeling.


Running your first R program is a significant step towards becoming proficient in the language. It introduces you to the basic workflow of writing, executing, and observing the results of your code. With practice and exploration, you'll gradually become more comfortable with R's syntax and capabilities, enabling you to tackle more complex tasks and projects.