0
0
R Programmingprogramming~10 mins

Running R code in R Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Running R code
Write R code
Run code in R environment
R interpreter reads code
Execute commands step-by-step
Display output or errors
End or repeat
This flow shows how R code is written, run, interpreted, executed, and output is shown.
Execution Sample
R Programming
x <- 5
print(x)
y <- x + 3
print(y)
This code assigns 5 to x, prints x, then assigns x+3 to y and prints y.
Execution Table
StepCode LineActionVariable StateOutput
1x <- 5Assign 5 to xx=5
2print(x)Print value of xx=5[1] 5
3y <- x + 3Calculate x+3 and assign to yx=5, y=8
4print(y)Print value of yx=5, y=8[1] 8
5EndNo more code to runx=5, y=8Execution finished
💡 All lines executed, program ends.
Variable Tracker
VariableStartAfter Step 1After Step 3Final
xundefined555
yundefinedundefined88
Key Moments - 2 Insights
Why does print(x) show 5 even though we didn't write 'return'?
In R, print() explicitly shows the value on screen. The execution_table row 2 shows print(x) outputs [1] 5.
What happens if we try to print(y) before assigning it?
R will give an error because y is undefined. The execution_table shows y is assigned only at step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the value of y after this step?
A3
B8
C5
Dundefined
💡 Hint
Check the 'Variable State' column in row 3 of execution_table.
At which step does the program print the number 8?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Look at the 'Output' column in execution_table rows.
If we change 'x <- 5' to 'x <- 10', what will be the output at step 4?
A13
B5
C8
D10
💡 Hint
y is assigned x + 3, so check variable_tracker for y after step 3.
Concept Snapshot
Running R code:
- Write code lines in R script or console
- Use <- to assign values
- Use print() to show output
- Run code line by line or all at once
- R executes commands and shows results or errors
Full Transcript
Running R code means writing commands in R language and executing them in an R environment. The R interpreter reads each line, runs it, and shows output or errors. For example, assigning x <- 5 stores 5 in x. Using print(x) shows 5 on screen. Then y <- x + 3 calculates 8 and stores in y. print(y) shows 8. This step-by-step execution helps understand how variables change and output appears.