Welcome back, everybody! I promised to show you an R Notebook, which is an excellent, awesome thing. It’s better than an RMD file; it’s an actual notebook file that will carry over the code that can be downloaded by your colleagues or by anyone else that’s collaborating on your project.
To further enhance your understanding of R programming and data manipulation, we recommend the following books (as an Amazon Associate, I may earn a small commission from these links):
- R for Data Science: Import, Tidy, Transform, Visualize, and Model Data
- Ace the Data Science Interview: 201 Real Interview Questions Asked By FAANG, Tech Startups, & Wall Street
- The Kaggle Book: Data analysis and machine learning for competitive data science
- Practical Statistics for Data Scientists: 50+ Essential Concepts Using R and Python
Getting Started with R Notebooks
To start a fresh project, follow these steps:
- Go to File -> New Project
- Choose New Directory -> New Project
- Give your project a name (e.g., First Notebook Project)
You’ll see the project file on the right-hand side, along with the R console as the project is created. However, we don’t have the notebook file yet. To create a new R notebook:
- Go to File -> New File -> R Notebook
- Save the notebook with a name (e.g., First Notebook)
The R notebook will look very familiar, like an R Markdown file, but R notebooks have so much more capability. Over the period of these tutorials, you’ll learn a lot of those features.
Understanding R Notebook Structure
In an R notebook, you’ll find:
- Metadata at the top: Contains title and output settings
- Text and code chunks: Text is written in Markdown, while code chunks are enclosed in backticks and has the programming language (R in this case) specified inside curly braces. RStudio can also run Python code and other languages when enabled.
Working with Code Chunks
To work with code chunks, you can:
- Run a code chunk by clicking the Play button next to it.
- Save the notebook to see changes in the HTML file, accessible via the right-hand side panel.
- View the notebook in a web browser to see the output, including the option to hide or show code chunks.
You can also customize code chunk settings:
- Give the code chunk a name for easier reference.
- Change the output options, such as showing only the output or hiding both code and output.
- Apply the new settings to see the changes in the HTML file.
Sharing R Notebooks
One of the best features of R notebooks is that you can share them with colleagues or collaborators. To share an R notebook:
- Save the notebook with all the necessary code chunks and output.
- Click on the “Download RMD file” option in the “Code” dropdown menu on the top right-hand corner of the HTML file.
- Share the downloaded RMD file along with any required datasets.
Remember that if you’re sharing a notebook that uses a custom dataset (e.g., a CSV file), you’ll need to share that dataset along with the notebook.
Unusual Facts about Data Science, Machine Learning, or R Programming
As promised, here are some unusual facts about the world of data science, machine learning, and R programming:
- R was named after its creators, Robert Gentleman and Ross Ihaka, whose first names start with the letter ‘R.’
- R is the 8th most popular programming language according to the TIOBE Index as of August 2021.
- Machine learning algorithms can be traced back to the 1950s but have become more popular and effective with the advent of big data and increased computational power.
I hope this tutorial helped you understand the power and flexibility of R Notebooks. Check out my YouTube channel, Cradle to Graver, for more tutorials like this. If you found this video useful, leave a comment below, and don’t