diff --git a/DESCRIPTION b/DESCRIPTION index aec30f7..22bcbb6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,6 @@ Imports: gridExtra, kwb.utils, remotes, - stringr, xml2 Suggests: knitr, diff --git a/NAMESPACE b/NAMESPACE index 4266ce6..089a2ef 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,11 +31,12 @@ importFrom(kwb.utils,asNoFactorDataFrame) importFrom(kwb.utils,catAndRun) importFrom(kwb.utils,createDirectory) importFrom(kwb.utils,hsShowPdf) +importFrom(kwb.utils,isTryError) importFrom(kwb.utils,preparePdf) +importFrom(kwb.utils,printIf) importFrom(kwb.utils,replaceFileExtension) importFrom(kwb.utils,selectElements) importFrom(remotes,available_packages) -importFrom(stringr,str_replace_all) importFrom(utils,download.file) importFrom(utils,getFromNamespace) importFrom(utils,read.table) diff --git a/R/abimo_functions_am.R b/R/abimo_functions_am.R index d056b5c..f11cbf2 100644 --- a/R/abimo_functions_am.R +++ b/R/abimo_functions_am.R @@ -263,15 +263,15 @@ abimo_xml_BER <- function ( } #' Helper function: replace value -#' @description searches for string for parameter=pattern_value -#' pattern and replaces with parameter="new_value" for all found -#' entries +#' +#' @description searches string for parameter= and replaces with +#' parameter= for all found entries +#' #' @param string string with ABIMO config #' @param new_value new parameter value #' @param parameter parameter name to search for (default: "etp") #' @param pattern_value pattern of value field (default: '\"\[0-9\]+?\\.?\[0-9\]+?\"') #' @return returns string with modified parameter = value -#' @importFrom stringr str_replace_all #' @export #' @examples #' ### Simple string @@ -281,15 +281,18 @@ abimo_xml_BER <- function ( #' ### Default ABIMO config #' config <- readLines(kwb.abimo::default_config()) #' replace_value(config, new_value = 100, parameter = "etp") -replace_value <- function(string, - new_value, - parameter = "etp", - pattern_value = "\"[0-9]+?\\.?[0-9]+?\"") { - - pattern <- sprintf("%s=%s", parameter, pattern_value) - replacement <- sprintf("%s=\"%s\"", parameter, new_value) - - stringr::str_replace_all(string, pattern, replacement) +replace_value <- function( + string, + new_value, + parameter = "etp", + pattern_value = "\"[0-9]+?\\.?[0-9]+?\"" +) +{ + gsub( + pattern = sprintf("%s=%s", parameter, pattern_value), + replacement = sprintf("%s=\"%s\"", parameter, new_value), + x = string + ) } #' change potential evaporation in Abimo config.xml diff --git a/man/replace_value.Rd b/man/replace_value.Rd index 05ae195..acc51b3 100644 --- a/man/replace_value.Rd +++ b/man/replace_value.Rd @@ -24,9 +24,8 @@ replace_value( returns string with modified parameter = value } \description{ -searches for string for parameter=pattern_value -pattern and replaces with parameter="new_value" for all found -entries +searches string for parameter= and replaces with +parameter= for all found entries } \examples{ ### Simple string