[1] "C:/Users/azetner/Documents/quarto-presentations"
2024-01-31
Work on More Than One Thing at a Time
Team Collaboration
Start and Stop
Documentation for Continuity
here()
:
here()
functionhere()
displays top-level folder location
Build a path to a file in a subdirectory and use it
[1] "C:/Users/azetner/Documents/quarto-presentations/presentations/20240131-RBP_images/analysisworkflow.png"
[1] "C:/Users/azetner/Documents/quarto-presentations/presentations/20240131-RBP_images"
arrow.file <- here("presentations/20240124-BWG_images/arrow_dataset.png")
file.info(arrow.file)["size"]
size
C:/Users/azetner/Documents/quarto-presentations/presentations/20240124-BWG_images/arrow_dataset.png 79441
here()
for pathsMaintain project separation
Settings stored in <NAME>.Rproj
.
Open Project in RStudio:
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Native
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
Everything that matters should be achieved through saved code
R --no-save --no-restore-data
Comment brief explanations
Functions first
Ruthlessly eliminate duplication
20220120_patient-exposure_control.csv
20220120_patient-exposure_treatment.csv
20220215_patient-exposure_control.csv
20220215_patient-exposure_treatment.csv
20220215_patient-info_control.csv
20220310_patient-info_control.csv
20220520_patient-info_treatment.csv
20220805_patient-info_control.csv
20230120_patient-info_treatment.csv
20230215_patient-info_treatment.csv
20230310_patient-exposure_control.csv
20230310_patient-exposure_treatment.csv
20230405_patient-exposure_control.csv
20230405_patient-exposure_treatment.csv
20230405_patient-info_control.csv
20230615_patient-info_treatment.csv
20230710_patient-info_control.csv
20230710_patient-info_treatment.csv
20230805_patient-info_treatment.csv
❯ ls -1 2022*
20220120_patient-exposure_control.csv
20220120_patient-exposure_treatment.csv
20220215_patient-exposure_control.csv
20220215_patient-exposure_treatment.csv
20220215_patient-info_control.csv
20220310_patient-info_control.csv
20220520_patient-info_treatment.csv
20220805_patient-info_control.csv
❯ ls -1 *info*
20220215_patient-info_control.csv
20220310_patient-info_control.csv
20220520_patient-info_treatment.csv
20220805_patient-info_control.csv
20230120_patient-info_treatment.csv
20230215_patient-info_treatment.csv
20230405_patient-info_control.csv
20230615_patient-info_treatment.csv
20230710_patient-info_control.csv
20230710_patient-info_treatment.csv
20230805_patient-info_treatment.csv
20230710_*patient-info_control*.csv
filedir <- here("presentations/20240131-RBP_images/fakedat/")
flist <- list.files(filedir, pattern = "info")
stringr::str_split_fixed(flist, "[_\\.]", 4)
[,1] [,2] [,3] [,4]
[1,] "20220215" "patient-info" "control" "csv"
[2,] "20220310" "patient-info" "control" "csv"
[3,] "20220520" "patient-info" "treatment" "csv"
[4,] "20220805" "patient-info" "control" "csv"
[5,] "20230120" "patient-info" "treatment" "csv"
[6,] "20230215" "patient-info" "treatment" "csv"
[7,] "20230405" "patient-info" "control" "csv"
[8,] "20230615" "patient-info" "treatment" "csv"
[9,] "20230710" "patient-info" "control" "csv"
[10,] "20230710" "patient-info" "treatment" "csv"
[11,] "20230805" "patient-info" "treatment" "csv"
01_import.R
20220820_wedding-photos.zip
result1.csv
, result2.csv
fig_3_a.png
Programs must be written for people to read, and only incidentally for machines to execute.
Rule 1: Comments should not duplicate the code
Rule 2: Good comments do not excuse unclear code.
Rule 3: If you can’t write a clear comment, there may be a problem with the code.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
.Rd
file generation% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add.R
\name{add}
\alias{add}
\title{Add together two numbers}
\usage{
add(x, y)
}
\arguments{
\item{x}{A number.}
\item{y}{A number.}
}
\value{
A numeric vector.
}
\description{
Add together two numbers
}
\examples{
add(1, 1)
add(10, 1)
}
R
man
.
├── DESCRIPTION
├── NAMESPACE
├── R
│ ├── cat_function.R
│ ├── cat_images.R
│ └── cats-package.R
├── README.md
└── man
├── add_cat.Rd
├── cat_function.Rd
├── cats.Rd
├── get_cat.Rd
└── here_kitty.Rd
Package: cats
Title: Cats
Version: 0.1
Author: Hilary Parker <hilary@etsy.com> [aut, cre]
Maintainer: Hilary Parker <hilary@etsy.com>
Authors@R: c( person("Hilary", "Parker", email = "hilary@etsy.com", role =
c("aut", "cre")))
Description: Mew.
Depends:
R (>= 3.0.2)
Imports:
httr,
ggplot2,
jpeg
License: MIT
LazyData: true
Suggests:
testthat
# Generated by roxygen2 (4.0.1.99): do not edit by hand
export(add_cat)
export(cat_function)
export(get_cat)
export(here_kitty)
import(ggplot2)
import(httr)
import(jpeg)
Why version control in data analysis projects?
CHANGELOG.txt
## 2016-04-08
* Switched to cubic interpolation as default.
* Moved question about family's TB history to end of questionnaire.
## 2016-04-06
* Added option for cubic interpolation.
* Removed question about staph exposure (can be inferred from blood test results).
Backup entire project folder
.
|-- project_name
| -- current
| -- ...project content as described earlier...
| -- 2016-03-01
| -- ...content of 'current' on Mar 1, 2016
| -- 2016-02-19
| -- ...content of 'current' on Feb 19, 2016
… please don’t do this
The only way to be certain that code written by someone else will run on your machine and will produce the same results is to replicate their environment