Creating a .yml file

The _site.yml file is where the instructions for the site and the site navigation live. yml was originally short for Yet Another Markup Language (yaml) and now stands for YAML Ain't Markup Language.

The yml file is simply a text file (use File > New file > Text File in RStudio). Save it as _site.yml or it won’t work. You can also create a regular RScript or Rmarkdown file and then choose the pop up menu in the bottom right of the writing pane to change it to YAML.

Content of the _site.yml file

The content of the _site.yml file should look something like the below.

name: "little-book-of-RStudio-websites"
output:
  html_document:
    theme: flatly # specifies the theme
navbar:
  left:
    - text: "Home"
      href: index.html
    - text: "Create a Project"
      href: project.html
    - text: "Set Build Options"
      href: build.html
    - text: "Create a _site.yml"
      href: create_yml.html
    - text: "Tables and Plots"
      href: tables_plots.html
    - text: "Include Images"
      href: images.html
    - text: "Embed a webpage"
      href: embed.html
    - text: "Themes"
      href: theme.html
    - text: "Publishing your site"
      href: publishing.html
output_dir: "." # if publishing on Github pages

Bear in mind that the more menu items we add the more the size of the navigation bar at the top will increase. This can lead to the page not displaying properly.

To solve this use sub-menus as in the _site.yml for this site (see below).

name: "Create a simple Rmarkdown website"
navbar:
  left:
    - text: "Home"
      href: index.html
    - text: "Getting Started"
      menu:
        - text: "Create a Project"
          href: project.html
        - text: "Set Build Options"
          href: build.html
        - text: "Create a _site.yml"
          href: create_yml.html
    - text: "Add Features"
      menu: 
        - text: "Tables and Plots"
          href: tables_plots.html
        - text: "Include Images"
          href: images.html
        - text: "Embed a webpage"
          href: embed.html
    - text: "Publish and Update"      
      menu: 
        - text: "Publishing"
          href: publishing.html
        - text: "Updating"
          href: updating.html
output_dir: "."

The key to this is to open a new menu heading as follows and then specify the items. text refers to the text for the menu button and the menu will group the pages that you specify. Note that the tab indents matter and if something goes wrong you have probably forgotten the - text for the menu heading or to indent uniformly.

- text: "Publish and Update"      
      menu: 
        - text: "Publishing"
          href: publishing.html
        - text: "Updating"
          href: updating.html