Skip to content

Commit

Permalink
add c4r vocabulary
Browse files Browse the repository at this point in the history
  • Loading branch information
miturbide committed Aug 14, 2019
1 parent f5fcd8c commit 3ae60a4
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Package: climate4R.UDG
Depends:
R(>= 3.5.0)
R(>= 3.5.0),
rJava
Imports:
utils,
RCurl
RCurl,
Suggests:
loadeR,
loadeR.ECOMS,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(C4R.vocabulary)
export(C4R.vocabulary.update)
export(UDG.datasets)
export(loginUDG)
importFrom(RCurl,getURL)
importFrom(rJava,J)
importFrom(utils,URLencode)
importFrom(utils,globalVariables)
importFrom(utils,packageDescription)
importFrom(utils,read.csv)
importFrom(utils,write.table)
1 change: 1 addition & 0 deletions R/loginUDG.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' Further details on registration for data access can be viewed in this \href{http://meteo.unican.es/trac/wiki/udg/registration}{example}.
#' @author J Bedia, M. Vega, A. Cofino
#' @export
#' @importFrom rJava J
#' @importFrom RCurl getURL
#' @importFrom utils URLencode

Expand Down
54 changes: 54 additions & 0 deletions R/vocabulary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' @title Show UDG vocabulary
#' @description Access the installed user's vocabulary
#' @return The vocabulary table, in the form of a data.frame
#' @seealso C4R.vocabulary.update, for the inclusion of new standard variables defined by the user
#' @note The function assumes that the user has read permission to the package installation directory
#' @author J Bedia
#' @references Standard name table of the CF convention: http://cfconventions.org/standard-names.html
#' @export
#' @importFrom utils read.csv
#' @examples
#' # Default built-in vocabulary
#' (voc <- C4R.vocabulary())
#' voc[grep("^ta", voc$identifier), ]

C4R.vocabulary <- function() {
read.csv(file.path(find.package("loadeR"), "vocabulary.txt"))
}

#' @title Include new variables in the vocabulary
#' @description Allows the introduction of new user defined entries in the default vocabulary
#' @return The built-in vocabulary is updated with the new entries appended at the end.
#' @param identifier A vector containing the identifier(s) of the new variable(s) to be appended to the dictionary.
#' @param standard_name A vector containing the standard name(s) of the new variable(s) to be appended to the dictionary.
#' @param units A vector containing the units of the new variable(s) to be appended to the dictionary.
#' @seealso C4R.vocabulary, to access the vocabulary contents
#' @export
#' @importFrom utils write.table
#' @author J Bedia
#' @references Standard name table of the CF convention: http://cfconventions.org/standard-names.html
#' @examples \dontrun{
#' # Inclusion of a new variable ("Total snowfall amount")
#' C4R.vocabulary.update(identifier = "prsn",
#' standard_name = "total snowfall amount",
#' units = "mm")
#' C4R.vocabulary()
#' # Inclusion of 2 new variables:
#' C4R.vocabulary.update(identifier = c("wap",
#' "plev"),
#' standard_name = c("lagrangian tendency of air pressure",
#' "air pressure"),
#' units = c("Pa.s-1",
#' "Pa"))
#' C4R.vocabulary()
#' }

C4R.vocabulary.update <- function(identifier, standard_name, units) {
ref <- C4R.vocabulary()
if (any(identifier %in% ref$identifier)) {
stop("One or more identifiers already exist in the vocabulary", call. = FALSE)
}
a <- cbind(identifier, standard_name, units)
write.table(a, append = TRUE, file = file.path(find.package("loadeR"), "vocabulary.txt"),
quote = FALSE, row.names = FALSE, sep = ",", col.names = FALSE)
}
31 changes: 31 additions & 0 deletions man/C4R.vocabulary.Rd

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

47 changes: 47 additions & 0 deletions man/C4R.vocabulary.update.Rd

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

0 comments on commit 3ae60a4

Please sign in to comment.