Hello World in R

Published on 27 April 2018 (Updated: 15 May 2023)

Welcome to the Hello World in R page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

cat("Hello, World!")

Hello World in R was written by:

This article was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

Fortunately, this task can be solved in a concise one-liner.

You can see the string "Hello, World!" as the argument of the function cat. This function does all the work. If you are familiar with Bash, you may already know the cat tool which prints the content of one or several files.

Analogously, you can pass one or several strings to the cat function which prints the input to the standard output. The function allows an optional argument sep that represents the separator to use when you pass multiple strings. As a consequence, the following is an equivalent alternative to the solution above:

cat("Hello", "World!", sep=", ")

In this call, "Hello" and "World!" are glued together by placing the specified separator ", " between the two strings, resulting in the desired output "Hello, World!".

Now, we know what we need to produce the output. The next section explains how we can also see the output of our program.

How to Run the Solution

In order to run the solution we need an R compiler first. Furthermore, we need a copy of Hello World in [R][1]. From within the directory in which we saved the copy, we run the following command on the command line:

Rscript hello-world.R        # Linux/Unix
R.exe hello-world.R          # Windows

Alternatively, you can try an online compiler if you want to save the time required for installing the R environment locally.