Skip to content

Commit

Permalink
Fix empty output issue for all queries other than single station
Browse files Browse the repository at this point in the history
The `%dopar%` loop did not create an object to be saved.

This commit fixes this bug.
  • Loading branch information
adamhsparks committed Jul 11, 2016
1 parent 9aebc0c commit 4b42358
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions R/get_GSOD.R
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,26 @@ get_GSOD <- function(years = NULL, station = NULL, country = NULL, path = "",
} else {
GSOD_XY <- .reformat(tmp, stations)
}
if (merge_station_years == FALSE) {
GSOD_XY <- GSOD_XY
}
} else {
cl <- parallel::makeCluster(parallel::detectCores() - 2)
doParallel::registerDoParallel(cl)
# For a country, the entire set or agroclimatology -----------------------
foreach::foreach(j = seq_len(length(GSOD_list))) %dopar% {
tmp <- try(.read_gz(paste0(td, "/", yr, "/", GSOD_list[j])))

# check to see if max_missing < missing days, if not, go to next
if (.check(tmp, yr, max_missing) == FALSE) {
GSOD_objects[[j]] <- .reformat(tmp, stations)
GSOD_XY <- data.table::rbindlist(foreach::foreach(
j = seq_len(length(GSOD_list))) %dopar% {
tmp <- try(.read_gz(paste0(td, "/", yr, "/", GSOD_list[j])))

# check to see if max_missing < missing days, if not, go to next
if (.check(tmp, yr, max_missing) == FALSE) {
.reformat(tmp, stations)
}
}
}
)
parallel::stopCluster(cl)
}

if (merge_station_years == FALSE) {
GSOD_XY <- GSOD_XY
} else {
GSOD_XY <- data.table::rbindlist(GSOD_objects)
}

#### Write to disk ---------------------------------------------------------
if (!is.null(station)) {
if (length(years) == 1) {
Expand Down

0 comments on commit 4b42358

Please sign in to comment.