searches string for parameter=<pattern_value> and replaces with parameter=<new_value> for all found entries
Usage
replace_value(
string,
new_value,
parameter = "etp",
pattern_value = "\"[0-9]+?\\.?[0-9]+?\""
)
Arguments
- string
string with ABIMO config
- new_value
new parameter value
- parameter
parameter name to search for (default: "etp")
- pattern_value
pattern of value field (default: '\"[0-9]+?\.?[0-9]+?\"')
Examples
### Simple string
string <- '<item bezirke="15,16,18,19,20" etp="807" etps="600" />'
replace_value(string, new_value = 100, parameter = "etp")
#> [1] "<item bezirke=\"15,16,18,19,20\" etp=\"100\" etps=\"600\" />"
replace_value(string, new_value = 100, parameter = "etps")
#> [1] "<item bezirke=\"15,16,18,19,20\" etp=\"807\" etps=\"100\" />"
### Default ABIMO config
config <- readLines(kwb.abimo::default_config())
replace_value(config, new_value = 100, parameter = "etp")
#> [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
#> [2] "<sections>"
#> [3] "\t<comment>"
#> [4] " Initiale Werte der Kalkulation von Abimo 3.2."
#> [5] " Genaueres ist der Dokumentation von Abimo entnehmen."
#> [6] "\t</comment>"
#> [7] "\t<section name=\"Infiltrationsfaktoren\">"
#> [8] "\t\t<item key=\"Dachflaechen\" value=\"0.00\" />"
#> [9] "\t\t<item key=\"Belaglsklasse1\" value=\"0.10\" />"
#> [10] "\t\t<item key=\"Belaglsklasse2\" value=\"0.30\" />"
#> [11] "\t\t<item key=\"Belaglsklasse3\" value=\"0.60\" />"
#> [12] "\t\t<item key=\"Belaglsklasse4\" value=\"0.90\" />"
#> [13] "\t</section>"
#> [14] "\t<section name=\"Bagrovwerte\">"
#> [15] "\t\t<item key=\"Dachflaechen\" value=\"0.05\" />"
#> [16] "\t\t<item key=\"Belaglsklasse1\" value=\"0.11\" />"
#> [17] "\t\t<item key=\"Belaglsklasse2\" value=\"0.11\" />"
#> [18] "\t\t<item key=\"Belaglsklasse3\" value=\"0.25\" />"
#> [19] "\t\t<item key=\"Belaglsklasse4\" value=\"0.40\" />"
#> [20] "\t</section>"
#> [21] "\t<section name=\"ErgebnisNachkommaStellen\">"
#> [22] " \t\t<item key=\"R\" value=\"3\" />"
#> [23] " \t\t<item key=\"ROW\" value=\"3\" />"
#> [24] " \t\t<item key=\"RI\" value=\"3\" />"
#> [25] " \t\t<item key=\"RVOL\" value=\"3\" />"
#> [26] " \t\t<item key=\"ROWVOL\" value=\"3\" />"
#> [27] " \t\t<item key=\"RIVOL\" value=\"3\" />"
#> [28] "\t\t<item key=\"FLAECHE\" value=\"0\" /> "
#> [29] "\t\t<item key=\"VERDUNSTUNG\" value=\"3\" />"
#> [30] "\t</section>"
#> [31] " <section name=\"Gewaesserverdunstung\">"
#> [32] ""
#> [33] " <item bezirke=\"1-6,13-15,17\" eg=\"825\" />"
#> [34] " <item bezirke=\"7-12,16,18-23\" eg=\"775\" />"
#> [35] ""
#> [36] " <!-- das ist der default wert (Bezirk=0) -->"
#> [37] " <item eg=\"775\" />"
#> [38] ""
#> [39] " </section>"
#> [40] " <section name=\"PotentielleVerdunstung\">"
#> [41] ""
#> [42] " <item bezirke=\"15,16,18,19,20\" etp=\"100\" etps=\"500\" />"
#> [43] " <item bezirke=\"8,9,10,12,21,22,23\" etp=\"100\" etps=\"505\" />"
#> [44] " <item bezirke=\"13,14,17\" etp=\"100\" etps=\"515\" />"
#> [45] " <item bezirke=\"2,3,4\" etp=\"100\" etps=\"520\" />"
#> [46] " <item bezirke=\"1,5,6,7,11\" etp=\"100\" etps=\"530\" />"
#> [47] ""
#> [48] " <!-- das ist der default wert (Bezirk=0) -->"
#> [49] " <item etp=\"100\" etps=\"530\" />"
#> [50] ""
#> [51] " </section>"
#> [52] ""
#> [53] " <section name=\"Diverse\">"
#> [54] "\t"
#> [55] "\t\t<!-- wenn 'true' wird BER (Beregnungshoehe landw. Nutzfl.) == 0 erzwungen, fuer alle Flaechentypen -->"
#> [56] " \t\t<item key=\"BERtoZero\" value=\"false\" />"
#> [57] ""
#> [58] " <!-- Niederschlags-Korrekturfaktor -->"
#> [59] " <item key=\"NIEDKORRF\" value=\"1.09\" />"
#> [60] "\t</section>"
#> [61] "</sections>"