From 3a973d0172ee41e165271fd3f4fbd763c3680c6b Mon Sep 17 00:00:00 2001 From: Hollos Roland Date: Thu, 24 Sep 2020 17:36:06 +0200 Subject: [PATCH] some bugfixing --- RBBGCMuso/R/calibrateMuso.R | 20 +++++++++++++------- calibrateMuso.R | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/RBBGCMuso/R/calibrateMuso.R b/RBBGCMuso/R/calibrateMuso.R index 0deefa5..2ac1992 100644 --- a/RBBGCMuso/R/calibrateMuso.R +++ b/RBBGCMuso/R/calibrateMuso.R @@ -16,10 +16,10 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, maxLikelihoodEpc=TRUE, pbUpdate = setTxtProgressBar, method="GLUE",lg = FALSE, w=NULL, ...){ - - file.remove(list.files(path = settings$inputLoc, pattern="progress.txt", recursive = TRUE)) - file.remove(list.files(path = settings$inputLoc, pattern="preservedCalib.csv", recursive = TRUE)) - unlink("thread",recursive=TRUE) + future::plan(future::multisession) + file.remove(list.files(path = settings$inputLoc, pattern="progress.txt", recursive = TRUE, full.names=TRUE)) + file.remove(list.files(path = settings$inputLoc, pattern="preservedCalib.csv", recursive = TRUE, full.names=TRUE)) + unlink(file.path(settings$inputLoc,"thread"),recursive=TRUE) # ____ _ _ _ _ # / ___|_ __ ___ __ _| |_ ___ | |_| |__ _ __ ___ __ _ __| |___ @@ -94,9 +94,15 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, while(progress < iterations){ Sys.sleep(1) progress <- tryCatch(getProgress(), error=function(e){progress}) - pbUpdate(pb,as.numeric(progress)) + if(is.null(pb)){ + pbUpdate(as.numeric(progress)) + } else { + pbUpdate(pb,as.numeric(progress)) + } + } + if(!is.null(pb)){ + close(pb) } - close(pb) # ____ _ _ # / ___|___ _ __ ___ | |__ (_)_ __ ___ @@ -164,7 +170,7 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, copyToThreadDirs <- function(prefix="thread", numcores=parallel::detectCores()-1, runDir="."){ dir.create(file.path(runDir,prefix), showWarnings=TRUE) - fileNames <- grep("^thread.*", list.files(runDir), value=TRUE, invert=TRUE) + fileNames <- grep("^thread.*", list.files(runDir,full.names=TRUE), value=TRUE, invert=TRUE) invisible(sapply(1:numcores,function(corenum){ threadDir <- file.path(runDir,prefix,paste0(prefix,"_",corenum)) dir.create(threadDir, showWarnings=FALSE) diff --git a/calibrateMuso.R b/calibrateMuso.R index 46c46e8..8df08d0 100644 --- a/calibrateMuso.R +++ b/calibrateMuso.R @@ -21,7 +21,6 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, # \____|_| \___|\__,_|\__\___| \__|_| |_|_| \___|\__,_|\__,_|___/ - copyToThreadDirs(thread_prefix, numcores = numcores, runDir = settings$inputLoc) # ____ _ _ _ @@ -33,7 +32,7 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, threadCount <- distributeCores(iterations, numCores) fut <- lapply(1:numCores, function(i) { - # future({ + future({ musoSingleThread(measuredData, parameters, startDate, endDate, formatString, dataVar, outLoc, @@ -42,7 +41,7 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, skipSpinup, plotName, modifyOriginal, likelihood, uncertainity, naVal, postProcString, i) - # }) + }) }) # __ ___ _ _ @@ -96,6 +95,7 @@ calibrateMuso <- function(measuredData, parameters = NULL, startDate = NULL, } copyToThreadDirs <- function(prefix="thread", numcores=parallel::detectCores()-1, runDir="."){ + browser() dir.create(file.path(runDir,prefix), showWarnings=TRUE) fileNames <- grep("^thread.*", list.files(runDir), value=TRUE, invert=TRUE) invisible(sapply(1:numcores,function(corenum){