Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed Feb 3, 2017
2 parents b5c4949 + 22b4e6a commit 1c780ad
Show file tree
Hide file tree
Showing 16 changed files with 1,304 additions and 355 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: getCRUCLdata
Type: Package
Title: Download and Use CRU CL2.0 Climatology Data in R
Version: 0.1.3
Version: 0.1.4
Authors@R: person(given = "Adam", family = "Sparks", email = "adamhsparks@gmail.com", role = c("aut", "cre"))
Description: Provides functions that automate downloading and importing
University of East Anglia Climate Research Unit (CRU) CL2.0 climatology data
Expand All @@ -14,7 +14,8 @@ Description: Provides functions that automate downloading and importing
East Anglia Climate Research Unit,
<https://crudata.uea.ac.uk/cru/data/hrg/tmc/readme.txt>.
License: MIT + file LICENSE
Depends: R (>= 3.0.0)
Depends:
R (>= 3.0.0)
Imports:
curl,
dplyr,
Expand All @@ -24,7 +25,7 @@ Imports:
tidyr,
utils
LazyData: TRUE
RoxygenNote: 6.0.0
RoxygenNote: 5.0.1
ByteCompile: TRUE
Suggests:
testthat,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# getCRUCLdata 0.1.4

## Minor Changes

* Correct fix bug in data frame object generation where elevation was improperly handled and function would stop

# getCRUCLdata 0.1.3

## Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion R/create_CRU_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ create_CRU_df <- function(pre = FALSE,
cache_dir)

CRU_df <-
.tidy_df(pre_cv, tmn, tmx, cache_dir)
.tidy_df(pre_cv, elv, tmn, tmx, cache_dir)

if (isTRUE(tmx)) {
tmx_df <- .calculate_tmx(CRU_df[, "tmp"], CRU_df[, "dtr"])
Expand Down
2 changes: 1 addition & 1 deletion R/get_CRU.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

files <- as.list(files[object_list %in% !isTRUE(files)])

# Download files -----------------------------------------------------------
# download files -----------------------------------------------------------
# adapted from my question on SO,
# http://stackoverflow.com/questions/40715370/
message(" \nDownloading requested data files.\n ")
Expand Down
37 changes: 25 additions & 12 deletions R/tidy_df.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#' @importFrom dplyr %>%
#' @noRd
.tidy_df <- function(pre_cv, tmn, tmx, cache_dir) {
.tidy_df <- function(pre_cv, elv, tmn, tmx, cache_dir) {
files <-
list.files(cache_dir, pattern = ".dat.gz$", full.names = TRUE)

# internal function to read files from cache directory and tidy them -------

# create list of tidied data frames ----------------------------------------
CRU_list <-
plyr::llply(.data = files,
.fun = .read_cache,
.pre_cv = pre_cv,
.progress = "text")
plyr::llply(
.data = files,
.fun = .read_cache,
.pre_cv = pre_cv,
.progress = "text"
)

# name the items in the list for the data that they contain ----------------
names(CRU_list) <- substr(basename(files), 12, 14)
Expand All @@ -23,10 +25,21 @@
wvars[[i]]
}

# lastly merge the data frames into one tidy (large) data frame ------------
CRU_df <- Reduce(function(...)
dplyr::full_join(..., by = c("lat", "lon", "month")), CRU_list)

# lastly merge the data frames into one tidy (large) data frame --------------
if (!isTRUE(elv)) {
CRU_df <- Reduce(function(...)
dplyr::full_join(..., by = c("lat", "lon", "month")), CRU_list)
} else if (isTRUE(elv) & length(CRU_list) > 1) {
elv_df <- as.data.frame(CRU_list["elv"])
names(elv_df) <- c("lat", "lon", "elv")
CRU_list[which(names(CRU_list) %in% c("elv"))] <- NULL
CRU_df <- Reduce(function(...)
dplyr::full_join(..., by = c("lat", "lon", "month")), CRU_list)
CRU_df <- dplyr::left_join(CRU_df, elv_df, by = c("lat", "lon"))
} else if (isTRUE(elv)) {
CRU_df <- as.data.frame(CRU_list["elv"])
names(CRU_df) <- c("lat", "lon", "elv")
}
return(CRU_df)

# cleanup before we go -----------------------------------------------------
Expand Down Expand Up @@ -80,7 +93,8 @@
value = "pre_cv",
dplyr::everything(),
-c(lat, lon))
x_df <- dplyr::left_join(x_df1, x_df2, by = c("lat", "lon", "month"))
x_df <-
dplyr::left_join(x_df1, x_df2, by = c("lat", "lon", "month"))
} else {
x_df <- x[, c(1:14)]
names(x_df) <- c("lat", "lon", month_names)
Expand All @@ -93,8 +107,7 @@
}
}
else if (ncol(x) == 3) {
names(x) <- c("lat", "lon", "elv")
x_df <- x * 1000
x_df <- data.frame(x[, c(1, 2)], x[, 3] * 1000)
}
return(x_df)
}
4 changes: 1 addition & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
0 errors | 0 warnings | 1 note

* This is minor release with the following changes
* Correct fix bug in raster object generation where the objects were incorrectly cropped
* Update documentation with ROxygen 6.0.0
* Minor edits to documentation for clarity
* Correct fix bug in data frame object generation where elevation was improperly handled and function would stop

* Check logs from local OSX, Appveyor and win-builder are all available from https://github.com/adamhsparks/checkresults/tree/master/getCRUCLdata

Expand Down
2 changes: 1 addition & 1 deletion docs/articles/getCRUCLdata.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_CRU_df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_CRU_stack.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/getCRUdata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1c780ad

Please sign in to comment.