Skip to content

Commit

Permalink
Merge branch 'atlas' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
miturbide committed Feb 24, 2020
2 parents 4dca605 + 2648334 commit 9ce8907
Show file tree
Hide file tree
Showing 25 changed files with 2,484 additions and 1,468 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: climate4R.UDG
Depends:
R(>= 3.5.0),
R(>= 3.3.0),
rJava
Imports:
utils,
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(C4R.vocabulary)
export(C4R.vocabulary.update)
export(UDG.datasets)
export(loginUDG)
importFrom(RCurl,getURL)
Expand All @@ -10,4 +8,3 @@ importFrom(utils,URLencode)
importFrom(utils,globalVariables)
importFrom(utils,packageDescription)
importFrom(utils,read.csv)
importFrom(utils,write.table)
32 changes: 20 additions & 12 deletions R/datasets.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#' @title Show UDG datasets
#' @description Access the installed user's vocabulary
#' @param which Which group of datasets. Choices are: "OBSERVATIONS", "REANALYSIS", "CMIP5", "CORDEX".
#' By default all are diplayed.
#' @description Lists the harmonized datasets that are accessible via UDG.
#' @param pattern Optional. Pattern in the dataset name as passed to function \code{\link{grep}} (case-insensitive).
#' @param full.info Default to FALSE. If TRUE, the complete URL is also displayed.
#' @return The datasets table, in the form of a \code{data.frame}
#' @note The function assumes that the user has read permission to the package installation directory
#' @author M Iturbide
Expand All @@ -12,16 +11,25 @@
#' # Default built-in datasets
#' str(UDG.datasets())
#' (sets <- UDG.datasets())
#' sets[grep("CORDEX-EUR44.*historical", sets$name), ]
#' # Pointing to a specific group of datasets
#' UDG.datasets(which = "CORDEX")$name
#' names(sets)
#' sets$OBSERVATIONS
#' # Using argument pattern
#' UDG.datasets(pattern = "CORDEX-EUR44.*historical")$name
#' UDG.datasets(pattern = "CORDEX-EUR44.*historical")
#' # Showing the full Url of the datasets
#' UDG.datasets(pattern = "E-OBS", full.info = TRUE)

UDG.datasets <- function(which = "", pattern = "") {
if (which == "") which <- c("OBSERVATIONS", "REANALYSIS", "CMIP5", "CORDEX")
df <- lapply(which, function(x) read.csv(file.path(find.package("climate4R.UDG"), paste0("datasets_", x,".txt")), stringsAsFactors = FALSE)[ ,1:3])
df <- do.call("rbind", df)
df[grep(pattern, df$name, ignore.case = TRUE),]
UDG.datasets <- function(pattern = "", full.info = FALSE) {
lf <- list.files(file.path(find.package("climate4R.UDG")), pattern = "datasets.*.txt", full.names = TRUE)
df <- lapply(lf, function(x) read.csv(x, stringsAsFactors = FALSE)[ ,1:3])
names(df) <- gsub(lf, pattern = ".*/datasets_|.txt", replacement = "")
matchlist <- lapply(df, function(x) x[grep(pattern, x$name, ignore.case = TRUE),])
sublist <- matchlist[unlist(lapply(matchlist, function(x) nrow(x) != 0))]
if (pattern != "") message("Matches found for: ", paste(names(sublist), collapse = " "))
if (!full.info) message("Label names are returned, set argument full.info = TRUE to get more information")
if (full.info) {
return(sublist)
} else {
return(lapply(sublist, function(x) x[["name"]]))
}
}

54 changes: 0 additions & 54 deletions R/vocabulary.R

This file was deleted.

32 changes: 0 additions & 32 deletions inst/datasets_CMIP5.txt

This file was deleted.

Loading

0 comments on commit 9ce8907

Please sign in to comment.