HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to RVariablesData TypesOperatorsCharacters (character)VectorsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ Character
📚 Vector
🔀 Condition & Loop
🧩 Function
R›Introduction to R

Introduction to R

First step into R, the language of statistics and data science: printing to the screen with cat and comments.

Simple enough for a 5-year-old to understand

print with cat

cat writes to the screen. Add "\n" to move to a new line; use sep="" for clean output.

Your first program
1
cat("Hello!\n", sep="")
Writes to the screen; \n new line.
Output / InputWrites to the screen; \n new line.
Output / Input
💡 Hint: print() also prints but adds [1] at the beginning; use cat for clean output.

Comment line

Example code
1
# This is a comment — it does not work.
# for single-line comments.
Comment# for single-line comments.
2
cat("Code is here\n", sep="")
Only this line runs.
Output / InputOnly this line runs.
CommentOutput / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

R is a programming language designed for statistics and data analysis. It began development in 1993 at the University of Auckland and is widely used today in academia, pharmaceutical research, public statistical agencies, and data journalism.

What sets R apart from general-purpose languages is that statistics are at the core of the language. Concepts like vectors, data frames, and missing values are not added-on libraries, but part of the language itself. Calculating means, building regressions, or drawing plots are one-line tasks.

This specialization comes with a price: some of R's behaviors seem strange to those coming from general-purpose languages. Indices start at one, short vectors are silently recycled, and the arrow sign is used for assignment. These are not bugs, but design choices born from data analysis habits.

What you will learn

  • How the R program works
  • printing to the screen with print
  • The usage of the assignment operator
  • Writing comment lines
  • Case sensitivity

Who is this for?

  • Learners of statistics and data analysis
  • Researchers processing data in their academic work
  • Those looking for a tool where Excel falls short

When to use?

R is strong in exploratory data analysis, statistical modeling, graphic generation, and preparing reproducible reports.

It is not suitable for writing web services, mobile apps, or large-scale production systems; Python or other general-purpose languages are preferred for these tasks.

Common mistakes

Wrong

Print("Hello")

R is case-sensitive, and the function name is lowercase print. This code throws the error "could not find function \"Print\"" error. The same sensitivity applies to variable names: value and Value are two separate variables.

Correct

print("Hello")

Wrong

x < - 5
print(x)

The assignment operator is formed by writing the less-than and hyphen characters adjacent to each other. When you put a space in between, R reads this as a "x is less than minus five" comparison; it doesn't throw an error, but x is not defined and the next line says "object 'x' not found". Silent errors like this are the most annoying ones.

Correct

x <- 5
print(x)

Wrong

# This is a comment
// This is also a comment
print("Hello")

In R, comment lines only start with a hash sign; double slashes are a habit from other languages and throw a syntax error in R. R also does not have block comments; to comment out multiple lines, a hash is placed at the beginning of each line.

Correct

# This is a comment
# This is also a comment
print("Hello")

Frequently asked questions

Can I use an equals sign instead of an arrow for assignment?

It works in most places, but the community considers the arrow sign standard. The equals sign is used to specify argument names in function calls; using them interchangeably ruins readability. Almost all style guides recommend the arrow for assignment.

Are R and RStudio the same thing?

No. R is the language itself and its interpreter, while RStudio is a development environment that makes writing R easier. R works without RStudio, but conveniences like the plot panel, variable viewer, and report generation come with RStudio.

Do I have to write print?

Not in an interactive session: when you type an expression and run it, you see the result automatically. However, in a script file, loop, or function, this automatic printing does not activate; print must be explicitly called there.

Summary

R is designed for statistics and data analysis.

The language is case-sensitive.

The arrow sign is used for assignment.

Comments start with a hash, and there are no block comments.

Printing inside a script requires print.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code