Skip to content

Commit 56b4710

Browse files
authored
Merge pull request #7 from ethanwhite/pass-eden-path-to-get-eden-data
Allow non-default eden_path in update_water and get_eden_data
2 parents 561123b + f2521fc commit 56b4710

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

R/get_water_data.R

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
#'
33
#' @title Downloads new EDEN depth data, calculates covariates, appends to covariate file
44
#'
5+
#' @param eden_path path where the EDEN data should be stored
6+
#'
57
#' @export
68
#'
79

8-
get_eden_data <- function() {
9-
10+
get_eden_data <- function(eden_path = file.path("Water")) {
11+
1012
metadata <- get_metadata()
11-
last_download <- get_last_download() %>% dplyr::select(-X)
13+
last_download <- get_last_download(eden_path) %>% dplyr::select(-X)
1214

1315
if(identical(metadata,last_download)) {
1416
return(NULL)
1517
} else {
1618

1719
download_eden_depths()
18-
20+
1921
covariate_data <- read.table("Water/eden_covariates.csv", header = TRUE, sep = ",")
20-
new_covariates <- get_eden_covariates() %>%
22+
new_covariates <- get_eden_covariates(eden_path) %>%
2123
dplyr::bind_rows(get_eden_covariates(level="all")) %>%
2224
dplyr::bind_rows(get_eden_covariates(level="wcas")) %>%
2325
dplyr::select(year, region=Name, variable, value) %>%
@@ -32,7 +34,7 @@ covariate_data <- dplyr::filter(covariate_data, !year %in% new_covariates$year)
3234

3335
depth_data <- read.table("Water/eden_depth.csv", header = TRUE, sep = ",") %>%
3436
dplyr::mutate(date=as.Date(date))
35-
new_depths <- get_eden_depths() %>%
37+
new_depths <- get_eden_depths(eden_path) %>%
3638
dplyr::bind_rows(get_eden_depths(level="all")) %>%
3739
dplyr::bind_rows(get_eden_depths(level="wcas")) %>%
3840
dplyr::mutate(date=as.Date(date))
@@ -41,7 +43,7 @@ depth_data <- dplyr::filter(depth_data, !date %in% new_depths$date) %>%
4143
rbind(new_depths) %>%
4244
dplyr::arrange("date", "region")
4345

44-
update_last_download(metadata = metadata)
46+
update_last_download(eden_path = eden_path, metadata = metadata)
4547
}
4648

4749
return(list(covariate_data=covariate_data, depth_data=depth_data))
@@ -51,14 +53,16 @@ return(list(covariate_data=covariate_data, depth_data=depth_data))
5153
#'
5254
#' @title Writes new water data
5355
#'
56+
#' @param eden_path path where the EDEN data should be stored
57+
#'
5458
#' @export
5559
#'
5660

57-
update_water <- function() {
61+
update_water <- function(eden_path) {
62+
63+
data <- get_eden_data(eden_path)
5864

59-
data <- get_eden_data()
60-
61-
if(is.null(data)) {
65+
if(is.null(data)) {
6266
return(cat("...No new data..."))
6367
} else {
6468

0 commit comments

Comments
 (0)