Skip to content

Commit

Permalink
Add a progress bar for query load #203
Browse files Browse the repository at this point in the history
  • Loading branch information
gaow committed Nov 21, 2019
1 parent a3b32f6 commit 0c454eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion dscrutils/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Depends: R (>= 3.2.0)
Imports:
utils,
tools,
yaml
yaml,
progress,
R6
Suggests:
ggplot2,
dplyr,
Expand Down
2 changes: 2 additions & 0 deletions dscrutils/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export(read_dsc)
export(run_cmd)
export(save_session)
export(shiny_plot)
importFrom(R6,R6Class)
importFrom(progress,progress_bar)
importFrom(stats,as.formula)
importFrom(stats,na.omit)
importFrom(tools,file_ext)
Expand Down
27 changes: 19 additions & 8 deletions dscrutils/R/dscquery.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
#' # See also example("dscread").
#'
#' @importFrom utils read.csv
#' @importFrom progress progress_bar
#'
#' @export
#'
Expand Down Expand Up @@ -308,8 +309,6 @@ dscquery <- function (dsc.outdir, targets = NULL, module.output.all = NULL,
# ------------------------
# As a safeguard, we check for any duplicated column (or list
# element) names, and if there are any, we halt and report an error.
if (verbose)
cat("Importing dsc-query output.\n")
dat <- read.csv(outfile,header = TRUE,stringsAsFactors = FALSE,
check.names = FALSE,comment.char = "",
na.strings = "NA")
Expand All @@ -333,11 +332,12 @@ dscquery <- function (dsc.outdir, targets = NULL, module.output.all = NULL,
# form "module.variable:output". After this step, "dat" will become a
# nested list, in which each element dat[[i]][j]] is the value of
# target i in pipeline j.
if (verbose)
cat("Reading DSC outputs.\n")

dat.unextracted <- dat
if (verbose)
cat(paste0("Load DSC output table of dimension ", nrow(dat), " by ", ncol(dat), ".\n"))
if (!is.empty.result(dat))
dat <- read.dsc.outputs(dat,dsc.outdir,ignore.missing.files)
dat <- read.dsc.outputs(dat,dsc.outdir,ignore.missing.files,verbose)
dat <- remove.output.suffix(dat)

# EXTRACT FULL MODULE OUTPUTS
Expand All @@ -346,10 +346,15 @@ dscquery <- function (dsc.outdir, targets = NULL, module.output.all = NULL,
if (n > 0) {
full.outputs <- vector("list",n)
names(full.outputs) <- module.output.all

if (verbose) {
pb = progress_bar$new(format = "- Loading module outputs [:bar] :percent eta: :eta", total = n, clear = FALSE, width= 60)
} else {
pb = null_progress_bar$new()
}
# Extract the full module outputs for each selected module or
# module group.
for (i in module.output.all) {
pb$tick()
x <- dat[[paste(i,"output.file",sep = ".")]]
m <- length(x)
if (m > 0)
Expand Down Expand Up @@ -512,7 +517,7 @@ filter.by.condition <- function (dat, expr, targets) {
# This function is more complicated than it might seem from the
# description because it tries to read the targets efficiently by
# reading from each DSC output file no more than once.
read.dsc.outputs <- function (dat, dsc.outdir, ignore.missing.files) {
read.dsc.outputs <- function (dat, dsc.outdir, ignore.missing.files, verbose) {

# Convert the DSC query result to a nested list. Here we use a
# "trick", setting all missing values to NA with logical type. This
Expand Down Expand Up @@ -563,9 +568,15 @@ read.dsc.outputs <- function (dat, dsc.outdir, ignore.missing.files) {
if (!is.na(j))
out[[j]][[x]] <- NA
}

# Extract the outputs.
if (verbose) {
pb = progress_bar$new(format = "- Loading targets [:bar] :percent eta: :eta", total = n, clear = FALSE, width= 60)
} else {
pb = null_progress_bar$new()
}
for (i in files) {
pb$tick()
x <- import.dsc.output(i,dsc.outdir,ignore.missing.files)
if (!is.null(x))
for (j in names(out[[i]]))
Expand Down
5 changes: 5 additions & 0 deletions dscrutils/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ read_dsc <- function(infile) {
return(readRDS(infile))
}
}

#' @title A null progressbar, because currently `progressbar_enabled` feature does not work for `progress_bar`
#' @importFrom R6 R6Class
#' @keywords internal
null_progress_bar = R6Class("null_progress_bar", public = list(tick = function(...) {}))

0 comments on commit 0c454eb

Please sign in to comment.