From c91390455d091aa62f20202e3c0a00ee06a198a4 Mon Sep 17 00:00:00 2001 From: zfengms Date: Thu, 27 Jul 2017 11:37:11 -0700 Subject: [PATCH] fix subscription out of bounds error (#46) --- R/doAzureParallel.R | 50 ++++++++++++++++++++++++--------------------- R/utility.R | 34 ++++++++++++++++-------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/R/doAzureParallel.R b/R/doAzureParallel.R index e6e52fbf..1f0047c0 100644 --- a/R/doAzureParallel.R +++ b/R/doAzureParallel.R @@ -290,20 +290,22 @@ setVerbose <- function(value = FALSE){ endIndices[length(startIndices)] <- ntasks } - tasks <- lapply(1:length(endIndices), function(i){ - startIndex <- startIndices[i] - endIndex <- endIndices[i] - taskId <- paste0(id, "-task", i) - - .addTask(id, - taskId = taskId, - rCommand = sprintf("Rscript --vanilla --verbose $AZ_BATCH_JOB_PREP_WORKING_DIR/worker.R %s %s %s %s > %s.txt", "$AZ_BATCH_JOB_PREP_WORKING_DIR", "$AZ_BATCH_TASK_WORKING_DIR", jobFileName, paste0(taskId, ".rds"), taskId), - args = argsList[startIndex:endIndex], - envir = .doAzureBatchGlobals, - packages = obj$packages) - - return(taskId) - }) + if(length(endIndices) > 0){ + tasks <- lapply(1:length(endIndices), function(i){ + startIndex <- startIndices[i] + endIndex <- endIndices[i] + taskId <- paste0(id, "-task", i) + + .addTask(id, + taskId = taskId, + rCommand = sprintf("Rscript --vanilla --verbose $AZ_BATCH_JOB_PREP_WORKING_DIR/worker.R %s %s %s %s > %s.txt", "$AZ_BATCH_JOB_PREP_WORKING_DIR", "$AZ_BATCH_TASK_WORKING_DIR", jobFileName, paste0(taskId, ".rds"), taskId), + args = argsList[startIndex:endIndex], + envir = .doAzureBatchGlobals, + packages = obj$packages) + + return(taskId) + }) + } updateJob(id) @@ -386,18 +388,20 @@ setVerbose <- function(value = FALSE){ azureStorageUrl <- paste0("http://", storageCredentials$name,".blob.core.windows.net/", id) staticHtml <- "

Errors:

" - for(i in 1:length(failTasks)){ - if(failTasks[i] == 1){ + if(length(failTasks) > 0){ + for(i in 1:length(failTasks)){ + if(failTasks[i] == 1){ - stdoutFile <- paste0(azureStorageUrl, "/stdout") - stderrFile <- paste0(azureStorageUrl, "/stderr") - RstderrFile <- paste0(azureStorageUrl, "/logs") + stdoutFile <- paste0(azureStorageUrl, "/stdout") + stderrFile <- paste0(azureStorageUrl, "/stderr") + RstderrFile <- paste0(azureStorageUrl, "/logs") - stdoutFile <- paste0(stdoutFile, "/", id, "-task", i, "-stdout.txt", queryParameterUrl) - stderrFile <- paste0(stderrFile, "/", id, "-task", i, "-stderr.txt", queryParameterUrl) - RstderrFile <- paste0(RstderrFile, "/", id, "-task", i, ".txt", queryParameterUrl) + stdoutFile <- paste0(stdoutFile, "/", id, "-task", i, "-stdout.txt", queryParameterUrl) + stderrFile <- paste0(stderrFile, "/", id, "-task", i, "-stderr.txt", queryParameterUrl) + RstderrFile <- paste0(RstderrFile, "/", id, "-task", i, ".txt", queryParameterUrl) - staticHtml <- paste0(staticHtml, 'Task ', i, ' | ', "stdout.txt",' |', ' ', "stderr.txt",' | ', "R output",'
') + staticHtml <- paste0(staticHtml, 'Task ', i, ' | ', "stdout.txt",' |', ' ', "stderr.txt",' | ', "R output",'
') + } } } diff --git a/R/utility.R b/R/utility.R index 0b468e75..df53bc8f 100644 --- a/R/utility.R +++ b/R/utility.R @@ -55,23 +55,27 @@ getJobList <- function(jobIds = c()){ jobs <- listJobs(query = list("$filter" = filter, "$select" = "id,state")) print("Job List: ") - for(j in 1:length(jobs$value)){ - tasks <- listTask(jobs$value[[j]]$id) - count <- 0 - if(length(tasks$value) > 0){ - taskStates <- lapply(tasks$value, function(x) x$state == "completed") - - for(i in 1:length(taskStates)){ - if(taskStates[[i]] == TRUE){ - count <- count + 1 + if(length(jobs$value) > 0){ + for(j in 1:length(jobs$value)){ + tasks <- listTask(jobs$value[[j]]$id) + count <- 0 + if(length(tasks$value) > 0){ + taskStates <- lapply(tasks$value, function(x) x$state == "completed") + + if(length(taskStates) > 0){ + for(i in 1:length(taskStates)){ + if(taskStates[[i]] == TRUE){ + count <- count + 1 + } + } } - } - summary <- sprintf("[ id: %s, state: %s, status: %d", jobs$value[[j]]$id, jobs$value[[j]]$state, ceiling((count/length(tasks$value) * 100))) - print(paste0(summary, "% ]")) - } - else { - print(sprintf("[ id: %s, state: %s, status: %s ]", jobs$value[[j]]$id, jobs$value[[j]]$state, "No tasks were run.")) + summary <- sprintf("[ id: %s, state: %s, status: %d", jobs$value[[j]]$id, jobs$value[[j]]$state, ceiling((count/length(tasks$value) * 100))) + print(paste0(summary, "% ]")) + } + else { + print(sprintf("[ id: %s, state: %s, status: %s ]", jobs$value[[j]]$id, jobs$value[[j]]$state, "No tasks were run.")) + } } } }