From 4fefa79dd04f42366b2e9205802e9743c4fbf6c3 Mon Sep 17 00:00:00 2001 From: Nick Golding Date: Wed, 9 Sep 2015 20:53:58 +0100 Subject: [PATCH 1/3] fixing silly RunModels bug --- R/zoonHelpers.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/zoonHelpers.R b/R/zoonHelpers.R index 5122037..2ebb458 100644 --- a/R/zoonHelpers.R +++ b/R/zoonHelpers.R @@ -160,7 +160,7 @@ RunModels <- function(df, modelFunction, paras, workEnv){ paras), envir = workEnv) - pred <- ZoonPredict(.model$model, + pred <- ZoonPredict(modelFold, newdata = df[df$fold == i, 6:NCOL(df), drop = FALSE]) dfOut$predictions[df$fold == i] <- pred @@ -175,7 +175,7 @@ RunModels <- function(df, modelFunction, paras, workEnv){ # If external validation dataset exists, predict that;. if(0 %in% df$fold){ - pred <- ZoonPredict(.model$model, + pred <- ZoonPredict(modelFold, newdata = df[df$fold == 0, 6:NCOL(df), drop = FALSE]) dfOut$predictions[df$fold == 0] <- pred From 160a485bcdec311a51c0d82d4b067388565349b6 Mon Sep 17 00:00:00 2001 From: Nick Golding Date: Wed, 9 Sep 2015 21:04:47 +0100 Subject: [PATCH 2/3] fixing dummy chain function --- R/zoonHelpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zoonHelpers.R b/R/zoonHelpers.R index 2ebb458..04304d8 100644 --- a/R/zoonHelpers.R +++ b/R/zoonHelpers.R @@ -353,7 +353,7 @@ ExtractAndCombData <- function(occurrence, ras){ Chain <- function(...){ ans <- list(...) - attr(ans, 'isChain') <- TRUE + attr(ans, 'chain') <- TRUE return (ans) } From 5f9925b0dddd4f1c81b82f8ba0b92e9343d62387 Mon Sep 17 00:00:00 2001 From: Nick Golding Date: Wed, 9 Sep 2015 21:55:34 +0100 Subject: [PATCH 3/3] aligning texts with zoonModel class --- tests/testthat/test-ChangeWorkflow.R | 2 +- tests/testthat/test-wholeWorkflows.R | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/testthat/test-ChangeWorkflow.R b/tests/testthat/test-ChangeWorkflow.R index ce6fdd6..2fdaeb7 100644 --- a/tests/testthat/test-ChangeWorkflow.R +++ b/tests/testthat/test-ChangeWorkflow.R @@ -91,6 +91,6 @@ test_that('RerunWorkflow works', { expect_true(all.equal(w1, w2)) - }) + diff --git a/tests/testthat/test-wholeWorkflows.R b/tests/testthat/test-wholeWorkflows.R index 41969e9..fd83026 100644 --- a/tests/testthat/test-wholeWorkflows.R +++ b/tests/testthat/test-wholeWorkflows.R @@ -21,7 +21,8 @@ test_that('simple, package data workflow works.', { expect_equal(names(work1$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer')) expect_equal(dim(work1$process.output[[1]][[1]]), c(269, 6)) - expect_is((work1$model.output[[1]])$model, c('glm', 'lm')) + expect_is((work1$model.output[[1]])$model, c('zoonModel')) + expect_is((work1$model.output[[1]])$model$model, c('glm', 'lm')) expect_is((work1$model.output[[1]])$data, c('data.frame')) expect_is(work1$report[[1]], 'RasterLayer') @@ -44,7 +45,8 @@ test_that('Check basic quoted workflow.', { expect_equal(names(work1$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer')) expect_equal(dim(work1$process.output[[1]][[1]]), c(269, 6)) - expect_is((work1$model.output[[1]])$model, c('glm', 'lm')) + expect_is((work1$model.output[[1]])$model, c('zoonModel')) + expect_is((work1$model.output[[1]])$model$model, c('glm', 'lm')) expect_is((work1$model.output[[1]])$data, c('data.frame')) expect_is(work1$report[[1]], 'RasterLayer') @@ -72,7 +74,8 @@ test_that('modules downloading data work', { expect_true(all(work2$occurrence.output[[1]][,'latitude'] > 45)) expect_true(all(work2$occurrence.output[[1]][,'type']=='presence')) expect_is(work2$covariate.output[[1]], 'RasterLayer') - expect_is((work2$model.output[[1]])$model, 'randomForest') + expect_is((work2$model.output[[1]])$model, 'zoonModel') + expect_is((work2$model.output[[1]])$model$model, 'randomForest') expect_is(work2$report[[1]], 'RasterLayer') }) @@ -195,7 +198,8 @@ test_that('simple, crossvalidation workflow works.', { expect_equal(names(workCross$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer')) expect_equal(dim(workCross$process.output[[1]]$df), c(269, 6)) - expect_is((workCross$model.output[[1]])$model, c('glm', 'lm')) + expect_is((workCross$model.output[[1]])$model, c('zoonModel')) + expect_is((workCross$model.output[[1]])$model$model, c('glm', 'lm')) expect_is(workCross$report[[1]], 'RasterLayer') }) @@ -230,7 +234,8 @@ test_that('chains work.', { expect_equal(names(chain1$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer')) expect_equal(dim(chain1$process.output[[1]]$df), c(457, 6)) - expect_is((chain1$model.output[[1]])$model, c('glm', 'lm')) + expect_is((chain1$model.output[[1]])$model, c('zoonModel')) + expect_is((chain1$model.output[[1]])$model$model, c('glm', 'lm')) expect_is(chain1$report[[1]], 'RasterLayer') expect_true(exists('chain2')) @@ -240,7 +245,8 @@ test_that('chains work.', { expect_equal(names(chain2$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer.1', 'layer.2')) expect_equal(dim(chain2$process.output[[1]]$df), c(269, 7)) - expect_is((chain2$model.output[[1]])$model, c('glm', 'lm')) + expect_is((chain2$model.output[[1]])$model, c('zoonModel')) + expect_is((chain2$model.output[[1]])$model$model, c('glm', 'lm')) expect_is(chain2$report[[1]], 'RasterLayer') expect_true(exists('chain4')) @@ -250,7 +256,8 @@ test_that('chains work.', { expect_equal(names(chain4$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer')) expect_equal(dim(chain4$process.output[[1]]$df), c(269, 6)) - expect_is((chain4$model.output[[1]])$model, c('glm', 'lm')) + expect_is((chain4$model.output[[1]])$model, c('zoonModel')) + expect_is((chain4$model.output[[1]])$model$model, c('glm', 'lm')) expect_is(chain4$report[[1]], 'list') @@ -273,10 +280,9 @@ test_that('workflow with mix of syntax works.', { expect_equal(names(workSyn$process.output[[1]]$df), c('value', 'type', 'fold', 'longitude', 'latitude', 'layer')) expect_equal(dim(workSyn$process.output[[1]][[1]]), c(269, 6)) - expect_is((workSyn$model.output[[1]])$model, c('glm', 'lm')) + expect_is((workSyn$model.output[[1]])$model, c('zoonModel')) + expect_is((workSyn$model.output[[1]])$model$model, c('glm', 'lm')) expect_is((workSyn$model.output[[1]])$data, c('data.frame')) expect_is(workSyn$report[[1]], 'list') }) - -