Using RMarkdown to create Sport Science Reports

Part of scientific communication involves written, visually pleasing reports. Most sport science jobs require individuals to compile (usually many!) reports on testing results, performance outputs or GPS summaries, for example. This can take a great deal of time in Excel or Microsoft Word by creating formulas, manually adjusting the colours within a figure or dragging and dropping to perfect the final layout. Reports are often needed on a weekly or monthly basis, resulting in a great deal of time spent on a task that could be automated.

Fortunately, RMarkdown exists to assist with report automation! RMarkdown documents are fully reproducible and fantastic for displaying analysis (including R Code) to your PhD supervisory team, for example. There are a variety of static and dynamic outputs supported, including .pdf, .html and .doc formats. RMarkdown can even be used to generate slides, scientfic articles, interactive dashboards, books and websites!

To demonstrate how RMarkdown could be used to communicate a daily wellness report, consider my example below. Please ensure you follow all the steps, as RMarkdown relies on a specific format to conduct and visualise analysis. Firstly:

  1. Ensure you have RStudio downloaded and setup on your machine.
  2. Within RStudio, click File -> New File -> RMarkdown.
  3. When the window pops up, select HTML as your Default Output Format
  4. A new RScript window will pop up, with an automatically generated format
  5. Click the “Knit” button to see what this example format entails.
  6. You will need to save the .Rmd file in an easy to access location. Try the desktop and save as “DailyWellnessReport” so we can edit this version!

You will see this report pops up within a new R window. Select “Open in Browser” to view the report in it’s entirety. Although the example provides an overview, below is a Sport Science example. Simply copy and paste ALL of this code, replacing and overriding the existing text and symbols within your DailyWellnessReport.Rmd document. Please ensure you install all packages listed below before running the report. To start, copy and paste all text from here into your RMarkdown file.

Once the above is copied exactly, click the “Knit” button within RStudio and a new window should pop up, visualising the data. The report should look like:

You should be able to hover over each athlete, to highlight their reported data. If you resize the window, open in your browser or view the .html on a tablet or phone, the screen will readjust to enhance readability. To change the font size, simply replace the number 11 with a value of your choice.

Creating .pdf reports is also possible within RMarkdown, but requires the pre-installation of TeX, a typesetting language that allows you to focus on WHAT you are writing rather than worrying about formatting as you go along, such as drafting a manuscript in Microsoft Word. Many journals accept TeX files and I highly recommend drafting papers in this format, if you enjoy coding. To achieve best results with RMarkdown and .pdf I highly recommend pre-installing LaTeX, free software that is designed for the production of technical and scientific documents. To use the following format of .pdf, LaTeX must be installed or the document will not “knit” together. To create a dummy report of an athlete’s GPS or LPS report, copy and paste the exact code below, either over-riding the above report or by selecting File -> New File -> RMarkdown (.pdf) within RStudio. A table of contents is included, so the user can easily click on each athlete’s name at the start of the document or on the left hand “bookmarks” side. The .pdf report is currently set to landscape but can be altered, simply by replacing the landscape text to portrait. To create the report, copy and paste the code here into RMarkdown.

Once you hit “Knit” the report, provided LaTeX is installed, should look like:

If your data is stored in GoogleSheets, you can read this direct into R via the following code:

# Load required package
# Open the GoogleSheet in your browser (may need authentication) and then call in R
# Call the sheet directly into R
RawData <- gs_title("WriteTheNameOfYourSheetHere")

Given the example reporting in .html or .pdf, how do you plan on using RMarkdown to generate your own reports?