Uh-oh!
analysis_draft_3_final.R
.Illustration by Allison Horst
Conflicted?
Many of us have had the experience of loading a package that contains a function with the same name as one our code relies on.
Use the conflicted
package to choose which to use.
Illustration from Tidy Data for reproducibility, efficiency, and collaboration by Julia Lowndes and Allison Horst
Instead, they should be saved as:
arrow
package to work with larger than memory data setsThe Tidyverse Style Guide is a great resource for style guidance.
Auto-formatting
Use cmd + shift + A
in R-studio to auto-format your code on the fly.
Sectioning your code makes it easy for you and others to find the part of the analysis that you’re looking for at a glance.
Auto-formatting
Use cmd + shift + R
in Rstudio to create a new collapsible section.
cannot open file 'important-data.csv': No such file or directory
? They probably didn’t set the directory for you!Desktop/Medical_files/hair-transplant/important-data.csv
. Be kind, use a relative file path instead.Relative paths specify locations starting from the current location.
# Relative file path to a dedicated folder with raw data files
setwd("~/example-repo/RAW")
read.csv("important-data.csv")
# Call on another R source file back at the root of the directory
setwd(".")
source("analysis.R")
# Save the results of the analysis in it's own folder
setwd("/Cleaned_data")
write.csv(data_output, "data_output.csv")
# Bad
spec_data |>
mutate(scatter_normalized = scatter / 2.8)
# Better
spec_data |>
# Normalize by dividing by constant from calibration
mutate(scatter_normalized = scatter / 2.8)
# Best
# Load analysis that generates constant
source("spec_calibration.R")
spec_data |>
# Normalize by dividing by constant from calibration
mutate(scatter_normalized = scatter / calibration_value)
Data Practices for Open Science