From 34d4915297faf6236479f0e6474f8aa6b8d4b416 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 20 Jun 2017 04:30:52 +0200 Subject: Fix generation of input files - Write header only if not appending - Write max_soil and max_ws for metabolites - Formatting --- R/PEC_sw_focus.R | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'R/PEC_sw_focus.R') diff --git a/R/PEC_sw_focus.R b/R/PEC_sw_focus.R index 77839ab..cbf182d 100644 --- a/R/PEC_sw_focus.R +++ b/R/PEC_sw_focus.R @@ -89,12 +89,26 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA, interception = match.arg(interception) # Write to txt file if requested + header <- c("Active Substance", "Compound", "Comment", + "Mol mass a.i.", "Mol mass met.", + "Water solubility", + "KOC assessed compound", "KOC parent compound", + "DT50", + "Max. in Water", + "Max. in Soil asessed compound", # we reproduce the typo... + "App. Rate", "Number of App.", "Time between app.", "App. Type", + "DT50 soil parent compound", "DT50 soil", + "DT50 water", "DT50 sediment", + "Region / Season", + "Interception class") + add_line <- function(x) cat(paste0(x, "\r\n"), file = txt, append = TRUE) if (file.exists(txt_file)) { if (append) { txt <- file(txt_file, "a") } else { if (overwrite) { txt <- file(txt_file, "w") + add_line(paste(header, collapse = "\t")) } else { stop("The file", txt_file, "already exists, and you did not request", "appending or overwriting it") @@ -102,24 +116,10 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA, } } else { txt <- file(txt_file, "w") + add_line(paste(header, collapse = "\t")) } on.exit(close(txt)) - add_line <- function(x) cat(paste0(x, "\r\n"), file = txt, append = TRUE) - # Write header to txt file - header <- c("Active Substance", "Compound", "Comment", - "Mol mass a.i.", "Mol mass met.", - "Water solubility", - "KOC assessed compound", "KOC parent compound", - "DT50", - "Max. in Water", - "Max. in Soil asessed compound", # we reproduce the typo... - "App. Rate", "Number of App.", "Time between app.", "App. Type", - "DT50 soil parent compound", "DT50 soil", - "DT50 water", "DT50 sediment", - "Region / Season", - "Interception class") - add_line(paste(header, collapse = "\t")) if (is.null(met)) { compound = parent$name @@ -188,6 +188,8 @@ PEC_sw_focus <- function(parent, rate, n = 1, i = NA, } else { run_numeric["mw_ai"] = parent$mw run_numeric["mw_met"] = met$mw + run_numeric["max_soil"] = 100 * met$max_soil + run_numeric["max_ws"] = 100 * met$max_ws run_numeric["Koc_parent"] = parent$Koc run_numeric["DT50_soil"] = met$DT50_soil run_numeric["DT50_soil_parent"] = parent$DT50_soil @@ -328,7 +330,8 @@ chent_focus_sw <- function(name, Koc, DT50_ws = NA, DT50_soil = NA, DT50_water = NA, DT50_sediment = NA, cwsat = 1000, mw = NA, max_soil = 1, max_ws = 1) { - list(name = name, Koc = Koc, DT50_ws = DT50_ws, DT50_soil = DT50_soil, - DT50_water = DT50_water, DT50_sediment = DT50_sediment, cwsat = cwsat, - mw = mw, max_soil = max_soil, max_ws = max_ws) + list(name = name, Koc = Koc, + DT50_ws = DT50_ws, DT50_soil = DT50_soil, DT50_water = DT50_water, + DT50_sediment = DT50_sediment, + cwsat = cwsat, mw = mw, max_soil = max_soil, max_ws = max_ws) } -- cgit v1.2.1