Skip to content

Commit

Permalink
Updating model run scripts for travis
Browse files Browse the repository at this point in the history
  • Loading branch information
jrawbits committed Aug 18, 2020
1 parent 7c647c6 commit 454be00
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 2 additions & 0 deletions build/config/VE-components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ Components:
Type: script
Path: sources
CRAN:
- futile.logger
- tryCatchLog
- import
- R6
- jsonlite
Expand Down
12 changes: 3 additions & 9 deletions build/travis/make-module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ then
fi

pushd $1
rm -rf inst/module_docs # Don't need these for testing; just confuses devtools::check
mkdir -p data # No error if already exists, but must exist to document/install

# TEST_SCRIPT=${2:-${VE_SCRIPT:-tests/scripts/test.R}}
# echo TEST_SCRIPT=${TEST_SCRIPT}
Rscript -e "devtools::check('.',cran=FALSE,error_on='error')"
# if [ -f ${TEST_SCRIPT} ]
# then
# echo Executing ${TEST_SCRIPT} in $(pwd)
# Rscript -e "tryCatch( source('${TEST_SCRIPT}') )"
# else
# echo ${TEST_SCRIPT} does not exist in $(pwd)
# fi
echo Documenting "(basename $(pwd))"
Rscript -e "devtools::document()" # estimates models, creates NAMESPACE, help docs
echo Installing "$(basename $(pwd))" to ${BUILD_LIB}
R CMD INSTALL -l "${BUILD_LIB}" . # Save the installed package for later use
popd
21 changes: 17 additions & 4 deletions build/travis/run-model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@ then
export R_LIBS_USER=${BUILD_LIB}:${R_LIBS_USER}
fi

MODEL_DIR=$(dirname $1)
MODEL_PATH=$1
MODEL_DIR=$(dirname $MODEL_PATH)
MODEL_DIR=${MODEL_DIR:-.}

pushd ${MODEL_DIR}
Rscript -e "tryCatch( source('$(basename $1)') )"
popd
RUNNER=/sources/tools/models.R

echo Running R to run the model...
Rscript -e << RUNSCRIPT
tryCatch( {
require(visioneval,quietly=TRUE)
cat("Importing model API\n")
import::here(openModel,.from='$RUNNER')
ve.runtime <- '/sources'
model <- openModel('$MODEL_PATH')
cat("Running model",model\$modelName,"\n")
model\$run()
}
)
RUNSCRIPT
2 changes: 0 additions & 2 deletions sources/framework/visioneval/R/module.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ savePackageDataset <- function(dataset,overwrite=TRUE,keep=FALSE,compress="xz")
cat("Saving '",dsname,"' to '",file,"' ... ",sep="")
save(list=dsname,file=file,compress=compress,envir=parent.frame())
if ( ! file.exists(file) ) { traceback(); stop("File NOT saved!\n") } else cat("Saved\n")
} else {
cat("Not overwriting, ")
}
} else if (build.phase == "BUILD" ) {
# During the BUILD phase, we won't keep the dataset unless explicitly requested.
Expand Down
17 changes: 5 additions & 12 deletions sources/tools/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# https://www.tidyverse.org/blog/2019/11/roxygen2-7-0-0/#r6-documentation
# https://roxygen2.r-lib.org/articles/rd.html#r6

tool.contents <- c("openModel","verpat","verspm","vestate","go")
tool.contents <- c("openModel","verpat","verspm","vestate")

requireNamespace("jsonlite")
requireNamespace("R6")
requireNamespace("visioneval")
requireNamespace("futile.logger")
requireNamespace("tryCatchLog")

# Function: ve.model.path
# Determine if parameter is a list of locations of run_model.R riles
Expand Down Expand Up @@ -125,7 +127,8 @@ ve.run.model <- function(verbose=TRUE,path=NULL) {
envir <- as.environment("ve.model")
}
self$status <- ""
tryCatch(
futile.logger::flog.threshold(futile.logger::WARN)
tryCatchLog::tryCatchLog(
{
self$status <- "Running"
sys.source("run_model.R",envir=envir)
Expand Down Expand Up @@ -708,13 +711,3 @@ vestate <- function(staged = FALSE) {
model$run()
model
}

go <- function(clear=1,path=1,verbose=TRUE) {
if ( ! dir.exists("models/JRSPM") ) {
rspm <- openModel("VERSPM")$copy("JRSPM")
} else {
rspm <- openModel("JRSPM")
rspm$clear(force=TRUE,path=clear)
}
rspm$run(path=path,verbose)
}

0 comments on commit 454be00

Please sign in to comment.