1.4 Global options

Depending on your personal preferences, you can set a few global options before you work on your website. These options should be set using options(name = value), and currently available options are presented in Table 1.1.

TABLE 1.1: Global options that affect the behavior of blogdown.
Option name Default Meaning
servr.daemon interactive() Use a daemonized server?
blogdown.author The default author of new posts
blogdown.ext .md Default extension of new posts
blogdown.subdir post A subdirectory under content/
blogdown.yaml.empty TRUE Preserve empty fields in YAML?

We recommend that you set these options in your R startup profile file. You can check out the help page ?Rprofile for more details, and here is a simplified introduction. A startup profile file is basically an R script that is executed when your R session is started. This is a perfect place to set global options, so you do not need to type these options again every time you start a new R session. You can use a global profile file ~/.Rprofile,15 or a per-project file .Rprofile under the root directory of your RStudio project. The former will be applied to all R sessions that you start, unless you have provided the latter to override it. The easiest way to create such a file is to use file.edit() in RStudio, e.g.,

# or file.edit('.Rprofile')

Suppose you always prefer writing Rmd posts (instead of the default *.md), and want the author of new posts to be “John Doe” by default. You can set these options in the profile file:

options(blogdown.ext = '.Rmd', blogdown.author = 'John Doe')

A nice consequence of setting these options is that when you use the RStudio addin “New Post,” the fields “Author,” “Subdirectory,” and “Format” will be automatically populated, so you do not need to manipulate them every time unless you want to change the defaults (occasionally).

R only reads one startup profile file. For example, if you have a .Rprofile under the current directory and a global ~/.Rprofile, only the former one will be executed when R starts up from the current directory. This may make it inconvenient for multiple authors collaborating on the same website project, since you cannot set author-specific options. In particular, it is not possible to set the blogdown.author option in a single .Rprofile, because this option should be different for different authors. One workaround is to set common options in .Rprofile under the root directory of the website project, and also execute the global ~/.Rprofile if it exists. Author-specific options can be set in the global ~/.Rprofile on each author’s computer.

# in .Rprofile of the website project
if (file.exists('~/.Rprofile')) {
  base::sys.source('~/.Rprofile', envir = environment())
# then set options(blogdown.author = 'Your Name') in ~/.Rprofile

Note that R will silently ignore the last line of your .Rprofile if it does not have a trailing newline, so please make sure you add at least one newline to the end of your .Rprofile.

  1. The tilde ~ denotes your home directory in your system.↩︎