The minimum elements of a defensive workflow and links to learn more.
This article overviews the minimum elements of a defensive workflow and points you to resources to learn more (video). Beyond onboarding to 2DII, this article should be useful if you suspect you’ve drifted into habits that slow you down or make your work more brittle (https://rstats.wtf/).
Use these settings:
Restart your R session often to confirm you can reproduce your results from a blank slate.
RStudio makes it easy to create new projects2 and launch recent projects3. To launch older projects it’s easiest to use a dedicated app like Alfred4.
Find your project’s files with here()
.
Use it as a drop-in replacement for
file.path()
, it will always locate the files relative to your project root. – https://here.r-lib.org/reference/here.html
library(here)
# Good
(path <- here("_posts", "2021-10-26-defensive-workflow", "data", "greeting.txt"))
#> [1] "/home/rstudio/2degreesinvesting.github.io/_posts/2021-10-26-defensive-workflow/data/greeting.txt"
readLines(path)
#> [1] "Hello world"
# Bad
(path <- "/a/brittle path/that/only/i/have/data/greeting.txt")
#> [1] "/a/brittle path/that/only/i/have/data/greeting.txt"
readLines(path)
#> Error in file(con, "r"): cannot open the connection
Name your files following these guidelines:
https://speakerdeck.com/jennybc/how-to-name-files
For attribution, please cite this work as
Lepore (2021, Oct. 26). Data science at 2DII: Onboarding to a defensive workflow. Retrieved from https://2degreesinvesting.github.io/posts/2021-10-26-defensive-workflow/
BibTeX citation
@misc{lepore2021onboarding, author = {Lepore, Mauro}, title = {Data science at 2DII: Onboarding to a defensive workflow}, url = {https://2degreesinvesting.github.io/posts/2021-10-26-defensive-workflow/}, year = {2021} }