#### Global chunk options -----------------------------

knitr::opts_chunk$set(
  eval       = TRUE,  # whether to run code in code chunk
  include    = TRUE,  # whether to include the chunk output
  echo       = FALSE,  # Whether to show code chunk in final output
  error      = TRUE,  # whether to display error messages
  message    = FALSE,  # whether to preserve messages
  warning    = FALSE,  # whether to preserve warnings
  comment    = NA,  # a character string to append at start of each line of 
                    # results in final document
  tidy       = FALSE,  # whether to tidy code chunks for display
  dpi        = 96,  # dots per inch in graphics when applicable
  fig.width  = 8,  # consistent width for figures
  fig.asp    = 0.618,  # the golden ratio, can be adjusted in individual chunks
  out.width  = "90%",  # controls the output size
  fig.align  = "center",  # give plot room to breathe
  # fig.path   = "figures/somedir/"  # file path to store plots
  R.options  = list(width = 70), 
  NULL
)


#### Other options --------------------------------

## Width for code chunks ---------------- 

options(width = 120)

## Scientific notation ---------------
# Find out what it is set to
# getOption("scipen")

# Turn off scientific notation
options(scipen = 999)

## define format ----------------
# If you don't define format here, you'll need put `format = "html"` in 
# every kable function.

options(knitr.table.format = "html")  # use this option when knitting html
# options(knitr.table.format = "latex")  # use this option when knitting pdf

## Options for printing and saving ----------------

# Use these with if statements later on to control whether files or plots get
# saved/re-written. Basically, a safety measure.

save_plots <- TRUE
write_files <- TRUE


#### Packages --------------------------------------
# Load the packages to be used.

## Define the repository for packages ----------------
options(repos = c(CRAN = "https://cran.rstudio.com"))

## universally useful packages ----------------
# if (!require("pacman")) {install.packages("pacman")}
# if (!require("devtools")) {install.packages("devtools")}

## github packages ----------------
# if (!require("lamisc")) {devtools::install_github("emilelatour/lamisc")}

## Load the list of packages ----------------
pacman::p_load(
  Hmisc,         # contains many functions useful for data analysis
  psych,         # a general purpose toolbox
  tidyverse,     # packages ggplot2, tibble, tidyr, readr, purrr, and dplyr 
  forcats,       # functions for factors, forcats is an anagram for factors
  broom,         # functions tidy(), glance(), augment()
  magrittr,      # includes the %<>% assignment-pipe (%>% is loaded from dplyr)
  rlang,         # For use in tidyevaluation
  readxl,        # read in excel files
  writexl,       # write excel files, zero dependency
  # xlsx,          # read, write, format Excel files
  openxlsx,      # read, write and edit XLSX files
  janitor,       # for working with dirty data
  lubridate,     # for working with dates and times
  stringr,       # handy string operations
  tableone,      # Create Table 1 to Describe Baseline Characteristics
  labelled,      # Work with labelled data
  mice,          # Multivariate Imputation by Chained Equations
  DT,            # render R objects as HTML tables
  knitr,         # A General-Purpose Package for Dynamic Report Generation in R
  kableExtra,    # Enahced table functions 
  flextable,     # easily create tables for reporting and publications
  officer,       # Used by flextable
  formattable,   # Create formattable vectors and data frames
  extrafont,     # Tools for using fonts
  ggthemes,      # Extra Themes, Scales and Geoms for 'ggplot2'
  ggsci,         # Scientific journal themed color palettes for 'ggplot2'
  gt,            # information-rich, publication-quality tables from R
  scales,        # Scale Functions for Visualization
  survival,      # core survival analysis routines
  survminer,     # drawing survival curves
  humaniformat,  # a parser for human names
  hrbrthemes,    # ggplot themes
  visdat,        # Preliminary data visualisation
  naniar,        # structures, summaries, and visualisations for missing data
  here,          # Constructs paths to your project's files
  glue,          # Glue strings to data in R
  fs,            # Cross-platform interface to file system operations
  varhandle,     # Functions for robust variable handling
  rel,           # reliability coefficients
  irr,           # reliability and agreement coefficients
  vcd,           # visualizing categorical data
  install = FALSE

  )

#### Other packages -----------------------------

library(lamisc)       # devtools::install_github("emilelatour/lamisc") 
library(latable)      # devtools::install_github("emilelatour/latable")
library(laviz)        # devtools::install_github("emilelatour/laviz") 
library(purposeful)   # devtools::install_github("emilelatour/purposeful")
library(redcaptools)  # devtools::install_github("emilelatour/redcaptools")


#### Some resources ---------------------------

#### Themes and colors -------------------------------

#### Load fonts --------------------------------
# extrafont::fonts()  # Vector of font family names
# extrafont::fonttable()  # Show entire table
# extrafont::font_import()  # imports fonts installed on the system
extrafont::loadfonts(device = "pdf", quiet = TRUE)

Overview

Load data


Data visualization


Analysis


Discussion

Reproducibility info

devtools::session_info()


emilelatour/lamisc documentation built on May 10, 2024, 8:38 a.m.