From 82fc90190280fb938fa9a8d40c147d045735076e Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Mon, 16 Oct 2023 13:59:59 -0500 Subject: [PATCH] made data and figure directories easier to change --- 01_download_data.R | 8 +++++++- 02_process_data.R | 4 ++-- 03_make_figures.R | 10 ++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/01_download_data.R b/01_download_data.R index 2babbe6..72843a3 100644 --- a/01_download_data.R +++ b/01_download_data.R @@ -3,7 +3,13 @@ library(nhdplusTools) library(sf) # set data dir -nhdplusTools_data_dir(dir = "data/hydrologic") +data_dir <- "data" +ifelse( + !dir.exists(file.path(getwd(), paste0(data_dir, "/hydrologic"))), + dir.create(file.path(getwd(), paste0(data_dir, "/hydrologic"), recursive = TRUE)), + FALSE) + +nhdplusTools_data_dir(dir = paste0(data_dir, "/hydrologic")) # load extent of map extent <- read.csv(file = "extent.csv") diff --git a/02_process_data.R b/02_process_data.R index 2fb1cf9..f0bf72a 100644 --- a/02_process_data.R +++ b/02_process_data.R @@ -10,7 +10,7 @@ for (layer in layers){ # load political boundaries political <- list(NULL) -political_boundaries <- list.files(path = "data/political_boundaries") +political_boundaries <- list.files(path = paste0(data_dir, "/political_boundaries")) for (boundary in political_boundaries) { - political[[boundary]] <- st_read(paste0("data/political_boundaries/", boundary)) + political[[boundary]] <- st_read(paste0(data_dir, "/political_boundaries/", boundary)) } diff --git a/03_make_figures.R b/03_make_figures.R index bef127d..c9591bf 100644 --- a/03_make_figures.R +++ b/03_make_figures.R @@ -1,19 +1,24 @@ # load libraries library(sf) +# set dir to save figures to +figure_dir <- "figures" +ifelse(!dir.exists(file.path(getwd(), figure_dir)), dir.create(file.path(getwd(), figure_dir)), FALSE) + +# set colors colors <- list(darkblue = "#062e57", lightblue = "#b1dcf3") # save figure -tiff(filename = "figures/map.tiff", +tiff(filename = paste0(figure_dir,"/map.tiff"), width = 11, height = 17, units = "in", res = 600, compression = "lzw") -png(filename = "figures/map.png", +png(filename = paste0(figure_dir, "/map.png"), width = 11, height = 17, units = "in", @@ -51,3 +56,4 @@ plot(sf::st_geometry(data$NHDFlowline), add = TRUE) # finish saving figure dev.off() +dev.off() \ No newline at end of file