R Markdown lets you mix text, code, and results in one file. It helps you make reports that update automatically when your data changes.
0
0
R Markdown document creation in R Programming
Introduction
You want to write a report that includes R code and its output together.
You need to share your data analysis with others in a clear, readable format.
You want to create documents that combine explanations, code, and graphs.
You want to make presentations or websites from your R code and results.
You want to keep your work organized and reproducible.
Syntax
R Programming
--- title: "Document Title" author: "Your Name" date: "2024-06-01" output: html_document --- # Section Title Some text here. ```{r} # R code chunk summary(cars) ```
The top part between --- is called the YAML header. It sets the document title, author, date, and output format.
Code chunks start with ```{r} and end with ```. Inside, you write R code that runs and shows results.
Examples
A basic document with a title and a code chunk that prints text.
R Programming
--- title: "My First Report" output: html_document --- This is a simple R Markdown document. ```{r} print("Hello, world!") ```
This document sets author and date, and will create a PDF report with a data summary.
R Programming
--- title: "Analysis" author: "Alex" date: "2024-06-01" output: pdf_document --- # Data Summary ```{r} summary(mtcars) ```
Example of making a presentation slide with a plot from R code.
R Programming
--- title: "Presentation" output: ioslides_presentation --- # Slide 1 Welcome to my presentation. ```{r} plot(cars) ```
Sample Program
This R Markdown document creates an HTML report with a title, author, date, and a summary of the iris dataset.
R Programming
--- title: "Simple R Markdown Example" author: "Friend" date: "2024-06-01" output: html_document --- # Introduction This document shows a summary of the <code>iris</code> dataset. ```{r} summary(iris) ```
OutputSuccess
Important Notes
You can change the output format in the YAML header to create HTML, PDF, Word, or slides.
Make sure to save your file with the .Rmd extension to use R Markdown.
Use the Knit button in RStudio to run the document and see the final report.
Summary
R Markdown combines text and R code in one file for easy reports.
Use YAML header to set title, author, date, and output format.
Write R code inside chunks marked by ```{r} and ```.