Skip to content

Commit

Permalink
#181 refactor registerISOCodelist
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Jan 2, 2025
1 parent f0fdd3d commit 4d092d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions R/ISOCodelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,29 +356,32 @@ getISOCodelist <- function(id){
#' @description \code{registerISOCodelist} allows to register a new codelist
#' registered in \pkg{geometa}
#'
#' @usage registerISOCodelist(refFile, id, force)
#' @usage registerISOCodelist(refFile, id, version, force)
#'
#' @param refFile ISO XML file handling the ISO codelist
#' @param id identifier of the ISO codelist
#' @param version the version of the metadata standard
#' @param force logical parameter indicating if registration has be to be forced
#' in case the identified codelist is already registered
#'
#' @examples
#' registerISOCodelist(
#' refFile = "http://www.isotc211.org/2005/resources/Codelist/ML_gmxCodelists.xml",
#' id = "LanguageCode",
#' version = "19139",
#' force = TRUE
#' )
#'
#' @author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#
registerISOCodelist <- function(refFile, id, force = FALSE){
registerISOCodelist <- function(refFile, id, version = c("19139", "19115-3"), force = FALSE){
version = match.arg(version)
cl <- getISOCodelist(id)
if(!is.null(cl)){
if(!force) stop(sprintf("ISOcodelist with id '%s' already exists. Use force = TRUE to force registration", id))
.geometa.iso$codelists[sapply(.geometa.iso$codelists, function(x){x$id == id})][[1]] <- ISOCodelist$new(refFile = refFile, id = id)
.geometa.iso$codelists[[version]][sapply(.geometa.iso$codelists[[version]], function(x){x$identifier$value == id})][[1]] <- ISOCodelist$new(refFile = refFile, id = id)
}else{
cl <- ISOCodelist$new(refFile, id)
.geometa.iso$codelists <- c(.geometa.iso$codelists, cl)
.geometa.iso$codelists[[version]] <- c(.geometa.iso$codelists[[version]], cl)
}
}
5 changes: 4 additions & 1 deletion man/registerISOCodelist.Rd

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

0 comments on commit 4d092d3

Please sign in to comment.