Hello World in R Programming Language

Our first program will print the classic “hello world” message. Here’s the full source code.

# This is a simple R program that prints "hello world"
print("hello world")

To run the program, save the code in a file named hello_world.R and then use the Rscript command.

$ Rscript hello_world.R
[1] "hello world"

Alternatively, you can run it interactively in the R console:

$ R
> print("hello world")
[1] "hello world"
> q()

In R, there isn’t a need to build or compile the program into binaries. You simply run the script directly using the R interpreter.

Now that we can run basic R programs, let’s learn more about the language.

查看推荐产品