--Jenny Bryan
Workflow: personal taste and habits.
Product: essence of your project.
Don't hardwire your workflow into your product.
The editor you use to write your R code.
The raw data.
The name of your home directory.
The R code someone needs to run on your raw data to get your results, including the explicit library() calls to load necessary packages.
The name of the home directory is workflow, not product.
home <- "C:/Users/Mauro/Documents/" # Workflow proj_path <- "path/to/project" paste0(home, proj_path)
Better
proj_path <- "path/to/project" fs::path_home_r(proj_path)
Best
fs::path_home_r("path", "to", "project")
It’s like agreeing that we will all drive on the left or the right. A hallmark of civilization is following conventions that constrain your behavior a little, in the name of public safety.
--Jenny Bryan
The Project folder contains all relevant files.
Any .R can run from a fresh R process with wd set to root.
Any .R creates all it needs, in its own workspace or folder
Any .R touches nothing it didn't create (e.g. doesn't install).
path_to_data <- "../datasets/my-data.csv"
pacman::p_load(random)
library(ggplot2) setwd("/Users/jenny/cuddly_broccoli/verbose_funicular/foofy/data") df <- read.delim("raw_foofy_data.csv") p <- ggplot(df, aes(x, y)) + geom_point() ggsave("../figs/foofy_scatterplot.png")
Use RStudio projects, and/or
Use the here package (works well with .Rmd files)
library(ggplot2) library(here) df <- read.delim(here("data", "raw_foofy_data.csv")) p <- ggplot(df, aes(x, y)) + geom_point() ggsave(here("figs", "foofy_scatterplot.png"))
Suggests the useR works in one long-running (not fresh) R process.
Does NOT, in fact, create a fresh R process -- it only deletes objects from the global workspace but leaves stuff that make your script vulnerable to hidden dependencies (e.g. packages, options, working directory).
Is hostile to anyone that you ask to help you with your R problems.
Start from blank slate.
Restart R very often.
Re-run your under-development script from the top. For long running processes:
saveRDS()
and read it with readRDS()
, orThe importance of these practices has a lot to do with whether your code will be run by other people, on other machines, and in the future. If your current practices serve your purposes, then go forth and be happy
-- Jenny Bryan
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.