Loading Libraries for R Markdown

I typically load the same set of libraries when I start a project, and this is my first chunk in an *rmd file:

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
rm(list = ls())
library(kbtools)
vn <- c("kbtools", "rms", "ggplot2", "GGally", "boot", "Hmisc", "bbmle", "pdftools", "tidyverse", "arsenal", "dplyr", "MASS") 
sessionInfo()
lop <- names(sessionInfo()$otherPkgs); lop
libmgr("w")
libmgr("u")
lop <- names(sessionInfo()$otherPkgs); lop
libmgr("l", vn); 
lop <- names(sessionInfo()$otherPkgs); lop
options(scipen=5); options(warn = 0)
options(warn = -1) # ON for knitting; commented out for regular use.
rm(vn, lop)
getwd()
imgFolder <-"/img/Date/"
rootFolder <-"~/..."    ## Mac OS
b <- 1000
sessionInfo()
```

For a bare-bones, no-drama start, may also use this one-liner:

suppressMessages(suppressWarnings(sapply(c( "devtools",  "roxygen2", "knitr"), require, character.only = T)))

Leave a Reply