0
0
R Programmingprogramming~15 mins

Inline R code in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Inline R Code in R Markdown
📖 Scenario: You are preparing a simple R Markdown report to show some basic calculations inline with your text. This helps make your report dynamic and clear.
🎯 Goal: Create an R Markdown snippet that uses inline R code to display the result of a calculation inside a sentence.
📋 What You'll Learn
Create a numeric variable called num_apples with the value 5
Create a numeric variable called num_oranges with the value 3
Create a variable called total_fruits that sums num_apples and num_oranges
Write an R Markdown sentence that uses inline R code to show the value of total_fruits
💡 Why This Matters
🌍 Real World
Inline R code is used in R Markdown reports to show dynamic results inside text, making reports clear and automatically updated.
💼 Career
Data analysts and scientists use inline R code to create professional reports that update calculations automatically when data changes.
Progress0 / 4 steps
1
Create variables for fruit counts
Create a numeric variable called num_apples and set it to 5. Also create a numeric variable called num_oranges and set it to 3.
R Programming
Need a hint?

Use the assignment operator <- to assign values to variables.

2
Calculate total fruits
Create a variable called total_fruits that adds num_apples and num_oranges.
R Programming
Need a hint?

Use the + operator to add the two variables.

3
Write an R Markdown sentence with inline code
Write a character string variable called sentence that contains the text: "I have a total of `r total_fruits` fruits." Use backticks and r to include total_fruits inline as in R Markdown.
R Programming
Need a hint?

Use double quotes for the string and include `r total_fruits` exactly inside.

4
Print the sentence
Use print(sentence) to display the sentence with inline R code.
R Programming
Need a hint?

Use the print() function to show the sentence.