diff --git a/tools/R/amDataManage.R b/tools/R/amDataManage.R index 64c28106..af0a0dcd 100644 --- a/tools/R/amDataManage.R +++ b/tools/R/amDataManage.R @@ -391,57 +391,70 @@ amSubPunct <- function(vect, # [1] "heretique_crasy_namer_ssuss" -#' amUpdateDataListName +#' Update GRASS raster/vector name and SQLITE table name #' -#' Update GRASS raster/vector name and SQLITE table name, -#' based on modified tags field in data list. This function expect -#' a working GRASS environment and an accessmod config list. +#' This function updates names based on modified tags field in data list. +#' It expects a working GRASS environment and an AccessMod config list. #' -#' @param dataListOrig table with columns: "type displayClass tags origName class" . -#' @param dataListUpdate table with columns: "ttype displayClass tags origName class". If it contains modified tags value, origName is set as old name, new name is formed based on class and tags. -#' @param dbCon: path to sqlite db +#' @param dataListOrig data.frame with columns: "type", "displayClass", "tags", "origName", "class" +#' @param dataListUpdate data.frame with columns: "type", "displayClass", "tags", "origName", "class" +#' @param dbCon Path to SQLite database +#' @param config AccessMod configuration list #' -# @export +#' @return logical TRUE if updates were made, FALSE otherwise +#' @export amUpdateDataListName <- function(dataListOrig, dataListUpdate, dbCon, config) { - if (!is.null(dataListOrig) && !is.null(dataListUpdate)) { - tblO <- dataListOrig - tblU <- dataListUpdate - tblO[] <- lapply(tblO, as.character) - tblU[] <- lapply(tblU, as.character) - # test for empty or incorrect table - if (any(sapply(tblU, function(x) isTRUE(isEmpty(x) || x == "-")))) { - stop('Rename data : there is NA, missing char or "-" in update table') - } else { - # search for new tags - tblM <- anti_join(tblU, tblO) - if (!isTRUE(nrow(tblM) > 0)) { - return(FALSE) - } - # rename and get a list of changes - msgs <- apply(tblM, 1, function(x) { - # if not class DEM - if (!x["class"] == amGetClass(config$mapDem)) { - amRenameData( - type = x["type"], - new = amNewName(x["class"], x["tags"]), - old = x["origName"], - dbCon = dbCon - ) - } - }) + if (is.null(dataListOrig) || is.null(dataListUpdate)) { + return(FALSE) + } - # send a msg to ui - uiMsg <- tags$div( - style = "max-height:300px;overflow-y:scroll;", - tags$ul( - HTML(paste("