Skip to content

Commit 03994d3

Browse files
authored
Merge pull request #333 from USEPA/263-exclude-export_ready-0-from-tcplRun
263 added param to tcplRun to only process export_ready = 1 endpoints
2 parents 3e87c41 + 8ad6c82 commit 03994d3

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

Diff for: R/tcplRun.R

+23-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#' @param outfile Character of length 1, the name of the log file (optional)
2020
#' @param runname Character of length 1, the name of the run to be used in the
2121
#' outfile (optional)
22+
#' @param ready_only Boolean, whether to only process endpoints marked as
23+
#' export_ready = 1.
2224
#'
2325
#' @details
2426
#' The \code{tcplRun} function is the core processing function within the
@@ -44,8 +46,8 @@
4446
#' @importFrom parallel detectCores
4547
#' @export
4648

47-
tcplRun <- function(asid = NULL, slvl, elvl, id = NULL, type = "mc",
48-
mc.cores = NULL, outfile = NULL, runname = NULL) {
49+
tcplRun <- function(asid = NULL, slvl, elvl, id = NULL, type = "mc", mc.cores = NULL,
50+
outfile = NULL, runname = NULL, ready_only = FALSE) {
4951

5052
## Variable-binding to pass R CMD Check
5153
# acid <- aeid <- NULL
@@ -75,8 +77,17 @@ tcplRun <- function(asid = NULL, slvl, elvl, id = NULL, type = "mc",
7577
stop ("Invalid 'type' value.")
7678
}
7779

78-
if (!is.null(asid)) id <- tcplLoadAcid("asid", asid)$acid
79-
if (length(id) == 0) stop("No asid or id given.")
80+
if (!is.null(asid)) {
81+
acid_tbl <- tcplLoadAcid("asid", asid, add.fld = "export_ready")
82+
id <- if (ready_only) acid_tbl[export_ready == 1]$acid else acid_tbl$acid
83+
} else if (ready_only) {
84+
if (slvl < 4L) {
85+
id <- tcplLoadAcid("acid", id, add.fld = "export_ready")[export_ready == 1]$acid
86+
} else {
87+
id <- tcplLoadAeid("aeid", id, add.fld = "export_ready")[export_ready == 1]$aeid
88+
}
89+
}
90+
if (length(id) == 0) stop("No asid or id(s) given, or given id(s) do not exist. Check if 'ready_only = TRUE'.")
8091
id <- unique(id)
8192

8293
if (!is.null(outfile)) {
@@ -185,7 +196,10 @@ tcplRun <- function(asid = NULL, slvl, elvl, id = NULL, type = "mc",
185196
}
186197

187198
## Change ids from acid to aeid, if necessary
188-
if (slvl < 4L | !is.null(asid)) id <- tcplLoadAeid("acid", id)$aeid
199+
if (slvl < 4L | !is.null(asid)) {
200+
aeid_tbl <- tcplLoadAeid("acid", id, add.fld = "export_ready")
201+
id <- if (ready_only) aeid_tbl[export_ready == 1]$aeid else aeid_tbl$aeid
202+
}
189203
names(id) <- paste0("AEID", id)
190204
if (is.null(mc.cores)) ncores <- min(length(id), detectCores() - 1)
191205

@@ -300,7 +314,10 @@ tcplRun <- function(asid = NULL, slvl, elvl, id = NULL, type = "mc",
300314
}
301315

302316
## Change ids from acid to aeid, if necessary
303-
if (slvl < 2L | !is.null(asid)) id <- tcplLoadAeid("acid", id)$aeid
317+
if (slvl < 2L | !is.null(asid)) {
318+
aeid_tbl <- tcplLoadAeid("acid", id, add.fld = "export_ready")
319+
id <- if (ready_only) aeid_tbl[export_ready == 1]$aeid else aeid_tbl$aeid
320+
}
304321
names(id) <- paste0("AEID", id)
305322
if (is.null(mc.cores)) ncores <- min(length(id), detectCores() - 1)
306323

Diff for: man/tcplRun.Rd

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)