Create a default comment header template in R?

Is it possible to create a default comment header template in R for all new scripts? I generally include some standard info at the top of all my scripts and would like to automate the process of creating the comment header. For example:

################################################## ## Project: ## Script purpose: ## Date: ## Author: ################################################## 
asked Nov 15, 2016 at 17:30 578 4 4 silver badges 12 12 bronze badges

Assuming you are using rstudio (R and rstudio are independent pieces of software), you may have a look at the relatively new code snippets feature in rstudio, outlined here. It is not exactly right, but might get you pretty close.

Commented Nov 15, 2016 at 17:57

Thanks! I think this is actually a better option since it will allow me to make (and easily insert) comment headers with different formats (e.g. for function scripts, cleanup scripts, shiny apps, etc)

Commented Nov 15, 2016 at 18:44 Also, @lmo please upvote the question if you found it interesting/useful! Commented Nov 15, 2016 at 21:17

3 Answers 3

Following the suggestion from @lmo above, I created two new code snippets in RStudio by editing the snippets file located at Preferences > Code > Edit Snippets

Note: Code below the snippet definition must be indented using tab and not two spaces

Snippet 1: Comment header for new scripts

snippet header_script ################################################## ## Project: ## Script purpose: ## Date: ## Author: ################################################## 

Snippet 2: Comment header for sections of code within a script:

snippet header_section ## Section: ################################################## 

Now, whenever I want to insert a given header, I just start typing the snippet name (e.g. header_script ), select it from the autocomplete menu (do not type out in full), and hit enter to insert the comment header.