Skip to contents

This function prints R code to the console that can be copied and pasted into an analysis script or quarto file. It sets up standard libraries and directory paths. In interactive sessions, if clipr is installed, the code chunk is also copied to the clipboard.

Usage

setup_chunk(
  extra_libs = NULL,
  dir_name = "01",
  quiet = FALSE,
  clipboard = interactive()
)

Arguments

extra_libs

Character vector. Additional library names to load.

dir_name

Character string. The specific subdirectory for results (e.g., "01", "02").

quiet

boolean. If TRUE do not print the code chunk to the console (only attempt to copy to clipboard).

clipboard

boolean. If TRUE attempt to copy the code chunk to the clipboard using clipr. Defaults to interactive().

Value

Prints formatted code to console. Returns the character vector invisibly.

Examples

setup_chunk(extra_libs = "limma", clipboard = FALSE)
#> suppressPackageStartupMessages(library(here))
#> suppressPackageStartupMessages(library(coriell))
#> suppressPackageStartupMessages(library(data.table))
#> suppressPackageStartupMessages(library(ggplot2))
#> suppressPackageStartupMessages(library(patchwork))
#> suppressPackageStartupMessages(library(edgeR))
#> suppressPackageStartupMessages(library(SummarizedExperiment))
#> suppressPackageStartupMessages(library(limma))
#> 
#> 
#> datafiles <- here("results", "data-files", "01")
#> figures <- here("results", "figures", "01")
#> rdsfiles <- here("results", "rds-files", "01")
#> 
#> invisible(sapply(c(datafiles, figures, rdsfiles), dir.create, showWarnings = F, recursive = T))