From the course: Creating Reports and Presentations with R Markdown and RStudio

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Including code from script files

Including code from script files - RStudio Tutorial

From the course: Creating Reports and Presentations with R Markdown and RStudio

Start my 1-month free trial

Including code from script files

- [Instructor] It's often useful when writing our markdown reports to source scripts instead of embedding all of your code directly into the the .Rmd file. So if we think about a folder containing our R studio project, we'd have an R script which contains some parts of the code and a .Rmd file that runs the script via the function source. This means that you write your code in a .R script file and then in your .Rmd file, the code is run with the function source. Before going through the steps of sourcing scripts, let's think about some of the reasons why we might want to source code. There are two primary reasons for sourcing scripts: one is functional and the other is aesthetic. Sourcing scripts prevents code duplication, which helps to reduce errors and ensure you know what code is being run and when. Sourcing scripts also improves the general readability of your .Rmd files when you're writing them. It's extremely useful when you're writing large, complex reports to have your code…

Contents