Skip to content

Commit

Permalink
CRAN Version 0.8.0
Browse files Browse the repository at this point in the history
Added a global search convenience function.  Fixed a bug when a coordinate variable is not lat or  long and is decreasing.
  • Loading branch information
rmendels committed Nov 19, 2021
1 parent abe2409 commit b363390
Show file tree
Hide file tree
Showing 30 changed files with 406 additions and 160 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ tests/vcr_cassettes/griddap_fixes_user_inputs_2.yml
^LICENSE\.md$
vignettes/rerddap.Rmd
vignettes/Using_rerddap.Rmd
vignettes/rerddap.Rmd.org
vignettes/Using_rerddap.Rmd.org
man/figures
revdep/
^CRAN-RELEASE$
4 changes: 2 additions & 2 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This package was submitted to CRAN on 2021-08-17.
Once it is accepted, delete this file and tag the release (commit 526e71a).
This package was submitted to CRAN on 2021-11-19.
Once it is accepted, delete this file and tag the release (commit abe2409).
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: General purpose R client for 'ERDDAP' servers. Includes
'datasets', and fetch 'datasets', in either 'csv' or 'netCDF' format.
'ERDDAP' information:
<https://upwell.pfeg.noaa.gov/erddap/information.html>.
Version: 0.7.6
Version: 0.8.0
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain", role = "aut"),
Expand Down Expand Up @@ -35,7 +35,7 @@ Suggests:
testthat,
vcr (>= 0.2.6)
Enhances: taxize
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
X-schema.org-applicationCategory: Climate
X-schema.org-keywords: earth, science, climate, precipitation, temperature, storm, buoy, NOAA
X-schema.org-isPartOf: https://ropensci.org
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export(ed_search)
export(ed_search_adv)
export(eurl)
export(fipscounty)
export(global_search)
export(griddap)
export(info)
export(key_words)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
rerddap 0.8.0
=============

* Added global search function
* fixed bug when dataset has a decreasing coordinate that
is not latitude or longitude


rerddap 0.7.6
=============

Expand Down
81 changes: 81 additions & 0 deletions R/global_search.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#' @title global_search
#' @description Search for ERDDAP tabledap or griddap datasets from a list
#' of ERDDAP servers based on search terms.
#' @param query (character) Search terms
#' @param server_list (list of character) List of ERDDAP servers to search
#' @param which_service character) One of tabledep or griddap.
#' @return If successful a dataframe wih columns:
#' \itemize{
#' \item title - the dataset title
#' \item dataset_id - the datasetid on that ERDDAP server
#' \item url - base url of dataset ERDDAP server
#' }
#' if urls are valid, no match is found, will return no match found
#' else returns error message
#' @details Uses the 'reddap' function ed_search() to search over
#' the list of servers
#' @examples
#' # get list of servers know by
#' # https://irishmarineinstitute.github.io/awesome-erddap
#' # e_servers <- servers()$url
#' # select a couple to search
#' # e_servers <- e_servers[c(1, 40)]
#' # to meet CRAN time limits will only search 1 place
#' e_servers <- "https://coastwatch.pfeg.noaa.gov/erddap/"
#' test_query <- 'NOAA/NCDC Blended Monthly'
#' query_results <- global_search(test_query, e_servers, "griddap")
#' @seealso
#' \code{\link[crul]{HttpClient}}
#' @rdname global_search
#' @export
global_search <- function(query, server_list, which_service) {
# check that input is of correct type
check_arg(query, "character")
check_arg(server_list, "character")
check_arg(which_service, "character")
which_service <- match.arg(which_service, c("tabledap","griddap"), FALSE)
search_url <- list()
for (iserv in seq(1, length(server_list))) {
# set which server
my_serv <- server_list[iserv]
good_url <- TRUE
# will do two tests on the server
# First is if erddap is not in URL
test_url <- grepl('erddap', my_serv, fixed = TRUE)
if (!test_url) { # erddap not in url
print(paste('server URL ', my_serv), ' does not contain "erddap"')
print('will be removed from server list')
good_url <- FALSE
}
# test if URL reachable
if (good_url) {
test_url <- crul::HttpClient$new(my_serv)
test_url_head <- try(test_url$head(), silent = TRUE)
if (suppressWarnings(class(test_url_head)[1] == 'try-error')) {
print(paste(' server URL', my_serv, ' not responding'))
good_url <- FALSE
}
}
# good URL, responding, make query
if (good_url){
temp_list <- try(ed_search(query = query, url = my_serv,
which = which_service),
silent = TRUE)
class_error <- suppressWarnings(class(temp_list)[1] == 'try-error')
if(!class_error) {
temp_list <- temp_list$info
temp_names <- names(temp_list)
temp_list$url <- rep(my_serv, nrow(temp_list))
names(temp_list) <- c(temp_names, 'url')
search_url <- rbind(search_url, temp_list)
}
}
}
if(length(search_url) == 0) {
print('no search results found')
return('no search results found')
} else {
return(search_url)
}
}

7 changes: 4 additions & 3 deletions R/grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,13 @@ fix_dims <- function(dimargs, .info) {
dimargs[[i]] <- rev(dimargs[[i]])
}
}

## new
if (nm %in% c('latitude', 'longitude')) {
# if (nm %in% c('latitude', 'longitude')) {
if (nm != 'time') {
z <- unlist(strsplit(.info$alldata[[nm]]$value[1], ","))
spacing <- as.numeric(unlist(strsplit(z[3], "=")[[1]])[2])
if (spacing < 0) {
if ((!is.na(spacing)) & (spacing < 0)) {
if (!(dimargs[[i]][1] > dimargs[[i]][2])) {
dimargs[[i]] <- rev(dimargs[[i]])
}
Expand Down
9 changes: 5 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
## Test environments

* local macOS install, R 4.1.1
* rhub ubuntu, debian, solaris
* rhub ubuntu, debian, solaris, Apple Silicon (M1), macOS 11.6 Big Sur
* win-builder (devel and release)

## R CMD check results

1 Note due to change in maintainer.
OK from all checks

## Reverse dependencies

* No probelms with reverse dependencies.

---

New maintainer of package - Roy Mendelssohn
This version fixes a bug dealing with trailing slashes in URLs
This version fixes a bug dealing with coordinates that
are not lat-lon and are in decreasing order. Adds a new
search function.

Thanks!
Roy Mendelssohn
47 changes: 47 additions & 0 deletions man/global_search.Rd

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

Loading

0 comments on commit b363390

Please sign in to comment.