First line of every R script?

I use that almsot every single time I restart a Shiny application locally. I'm convinced it brings good juju.

My first line

```{r, include = F, echo = F}
Packages <- c("tidyverse", "forcats", "stringr", "broom")
lapply(Packages, library, character.only = TRUE)
rm(Packages)

Also I like the floating table of content, hence:


output: 
  html_notebook: 
    toc: yes
    toc_float: true
    fig_caption: true

Regarding the discussion of rm(ls = list(all = TRUE)) as first line:

  1. I think it is not problematic to use if, if you know what you are doing. The problem is that many scripts are shared and other people might not know about the caveeats. They might adapt this line without thinking about the consequences.
  2. A workaround by restarting the R-Session every time (also via keyboard shortcut) is recommended.

As a compromise for those that still want a "firstliner" (because maybe they are like me just too lazy) would be to introduce a command which directly restarts R and works from all GUIs/IDEs. Of course it should really do a restart and also refresh the environment (i.e. cleaning the search path and other environment settings [depending on the global/project settings]). The advantage would be, that people would really often restart R and might think about why this is necessary.

As far as I can see, there is no clean and easy solution so far...

https://stackoverflow.com/questions/6313079/quit-and-restart-a-clean-r-session-from-within-r/6315855