Workflow: Scripts & Projects

Clear Workspace, DON’T EDIT

Always start by clearing the workspace. This ensure objects created in other files are not used here.

rm(list = ls())

List Used Packages, EDIT

List all the packages that will be used in chunk below.

packages <- c("tidyverse")

Load Packages, DON’T EDIT

Install Missing

Any missing package will be installed automatically. This ensure smoother execution when run by others.

Installing Packages on Other People Machine

Be aware the people may not like installing packages into their machine automatically. This might break some of their previous code.

# Do NOT modify
install.packages(setdiff(packages, rownames(installed.packages())))
- There are no packages to install.

Load

Load all packages

# Do NOT modify
lapply(packages, require, character.only = TRUE)
[[1]]
[1] TRUE

13.1 Introduction

This chapter is about how to organize project files.

13.2 Diamond Example

diamonds |> 
  ggplot(aes(x = carat, y = price)) +
  geom_hex()

# ggsave("figures/diamonds.png")

# write_csv(diamonds, "data/diamonds.csv")