-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.R
More file actions
76 lines (64 loc) · 2.28 KB
/
Copy pathconfig.R
File metadata and controls
76 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ============================================================
# config.R
#
# Purpose: User-editable settings and shared setup for this pipeline.
# Inputs: None. Script 01 alone reads NASS_API_KEY from .Renviron.
# Outputs: Project settings, directories and shared helper functions.
# Assumptions: Run from the project root (the folder with the .Rproj).
# Workflow: Sourced first by every numbered script and 00_run_all.R.
# ============================================================
options(scipen = 999, digits = 4, stringsAsFactors = FALSE, tigris_use_cache = TRUE)
REQUIRED_PACKAGES <- c(
"beepr", "glue", "janitor", "lubridate", "peeblestoolbox",
"rnassqs", "scales", "sf", "tidyverse", "tigris", "viridis"
)
missing_packages <- REQUIRED_PACKAGES[
!vapply(REQUIRED_PACKAGES, requireNamespace, logical(1), quietly = TRUE)
]
if (length(missing_packages) > 0) {
stop(
"Install these required packages before running the pipeline: ",
paste(missing_packages, collapse = ", "),
call. = FALSE
)
}
suppressPackageStartupMessages({
library(tidyverse)
library(sf)
library(glue)
})
# User-editable analysis settings
START_YEAR <- 2000L
END_YEAR <- lubridate::year(Sys.Date())
COUNTY_ACREAGE_YEAR <- 2022L
COUNTY_BOUNDARY_YEAR <- 2024L
SELECTED_PEACH_STATES <- c("GA", "CA", "SC", "NJ", "PA", "MI")
SELECTED_BLUEBERRY_STATES <- c("GA", "WA", "OR", "MI", "NJ", "CA")
DEFAULT_PLOT_WIDTH <- 10
DEFAULT_PLOT_HEIGHT <- 6
DEFAULT_DPI <- 300
CAPTION_WRAP_WIDTH <- 105
WATERMARK_TEXT <- "NOT FOR PUBLICATION"
# Project directories
DATA_RAW_DIR <- "data_raw"
DATA_CLEAN_DIR <- "data_clean"
EXPORT_DIR <- "exports"
OUTPUT_DIR <- "outputs"
DOCS_DIR <- "docs"
LOG_DIR <- "logs"
PROJECT_DIRS <- c(
DATA_RAW_DIR, DATA_CLEAN_DIR, EXPORT_DIR, OUTPUT_DIR, DOCS_DIR, LOG_DIR,
file.path(DOCS_DIR, "data_dictionaries")
)
invisible(lapply(PROJECT_DIRS, dir.create, recursive = TRUE, showWarnings = FALSE))
# Attribution
SOURCE_NASS <- paste(
"Source: U.S. Department of Agriculture National Agricultural",
"Statistics Service (USDA NASS) Quick Stats."
)
AJC_CREDIT <- "Analysis & chart: Jennifer Peebles & Pete Corson/AJC"
# Project helpers
source(file.path("R", "functions_charts.R"))
source(file.path("R", "functions_maps.R"))
source(file.path("R", "functions_nass.R"))
source(file.path("R", "functions_qa.R"))