diff --git a/book_source/03_topical_pages/94_docker/04_models.Rmd b/book_source/03_topical_pages/94_docker/04_models.Rmd index 205098b4593..8054671922e 100644 --- a/book_source/03_topical_pages/94_docker/04_models.Rmd +++ b/book_source/03_topical_pages/94_docker/04_models.Rmd @@ -55,7 +55,7 @@ It is important values for `type` and `version` are set correct. The PEcAn code To build the docker image, we use a Dockerfile (see example below) and run the following command. This command will expect the Dockerfile to live in the model specific folder and the command is executed in the root pecan folder. It will copy the content of the pecan folder and make it available to the build process (in this example we do not need any additional files). -Since we can have multiple different versions of a model be available for PEcAn we ar using the following naming schema `pecan/model--:-:= 0.3.0","models/biocro","Suggests",FALSE "mockery",">= 0.4.3","base/db","Suggests",FALSE "MODISTools",">= 1.1.0","modules/data.remote","Imports",FALSE diff --git a/modules/meta.analysis/DESCRIPTION b/modules/meta.analysis/DESCRIPTION index 3a7705c7610..b231707a04b 100644 --- a/modules/meta.analysis/DESCRIPTION +++ b/modules/meta.analysis/DESCRIPTION @@ -27,16 +27,17 @@ Description: The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific Imports: coda (>= 0.18), lattice, - PEcAn.utils, + MASS, PEcAn.DB, PEcAn.logger, - MASS, PEcAn.settings, + PEcAn.utils, rjags Suggests: ggmcmc, ggplot2, knitr (>= 1.42), + mockery, rmarkdown (>= 2.19), testthat (>= 1.0.2) SystemRequirements: JAGS diff --git a/modules/meta.analysis/R/meta.analysis.R b/modules/meta.analysis/R/meta.analysis.R index 290ef2391d7..e150b1f5687 100644 --- a/modules/meta.analysis/R/meta.analysis.R +++ b/modules/meta.analysis/R/meta.analysis.R @@ -9,7 +9,7 @@ ##' Trait Meta-analysis ##' -##' Runs heirarchical meta-analysis of plant trait data +##' Runs hierarchical meta-analysis of plant trait data ##' ##' `pecan.ma` runs a hierarchical Bayesian meta-analytical model. ##' This model combines prior information with data from studies on the particular species or group of interest. diff --git a/modules/meta.analysis/R/rename_jags_columns.R b/modules/meta.analysis/R/rename_jags_columns.R index d18fc5bb453..43d22ef7b0e 100644 --- a/modules/meta.analysis/R/rename_jags_columns.R +++ b/modules/meta.analysis/R/rename_jags_columns.R @@ -8,7 +8,7 @@ #------------------------------------------------------------------------------- ##-----------------------------------------------------------------------------# -##' renames the variables within output data frame trait.data +##' Renames the variables within output data frame trait.data ##' ##' @param data data frame to with variables to rename ##' diff --git a/modules/meta.analysis/R/run.meta.analysis.R b/modules/meta.analysis/R/run.meta.analysis.R index ec208a48a3b..65afcdf61bd 100644 --- a/modules/meta.analysis/R/run.meta.analysis.R +++ b/modules/meta.analysis/R/run.meta.analysis.R @@ -166,7 +166,7 @@ run.meta.analysis.pft <- function(pft, iterations, random = TRUE, threshold = 1. ##--------------------------------------------------------------------------------------------------## ##' Run meta analysis ##' -##' This will use the following items from setings: +##' This will use the following items from settings: ##' - settings$pfts ##' - settings$database$bety ##' - settings$database$dbfiles diff --git a/modules/meta.analysis/man/pecan.ma.Rd b/modules/meta.analysis/man/pecan.ma.Rd index 0ed7a41f4ff..3029bd7d4e5 100644 --- a/modules/meta.analysis/man/pecan.ma.Rd +++ b/modules/meta.analysis/man/pecan.ma.Rd @@ -47,7 +47,7 @@ as well as Y, SE, and n for each observation or summary statistic.} four chains with 5000 total samples from posterior } \description{ -Runs heirarchical meta-analysis of plant trait data +Runs hierarchical meta-analysis of plant trait data } \details{ \code{pecan.ma} runs a hierarchical Bayesian meta-analytical model. diff --git a/modules/meta.analysis/man/rename_jags_columns.Rd b/modules/meta.analysis/man/rename_jags_columns.Rd index 5a53963c293..7172345230f 100644 --- a/modules/meta.analysis/man/rename_jags_columns.Rd +++ b/modules/meta.analysis/man/rename_jags_columns.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/rename_jags_columns.R \name{rename_jags_columns} \alias{rename_jags_columns} -\title{renames the variables within output data frame trait.data} +\title{Renames the variables within output data frame trait.data} \usage{ rename_jags_columns(data) } @@ -10,7 +10,7 @@ rename_jags_columns(data) \item{data}{data frame to with variables to rename} } \description{ -renames the variables within output data frame trait.data +Renames the variables within output data frame trait.data } \seealso{ used with \code{\link[PEcAn.MA]{jagify}}; diff --git a/modules/meta.analysis/man/run.meta.analysis.Rd b/modules/meta.analysis/man/run.meta.analysis.Rd index 23650d59896..e0e7e5d4fad 100644 --- a/modules/meta.analysis/man/run.meta.analysis.Rd +++ b/modules/meta.analysis/man/run.meta.analysis.Rd @@ -40,7 +40,7 @@ nothing, as side effect saves \code{trait.mcmc} created by and post.distns.Rdata, respectively } \description{ -This will use the following items from setings: +This will use the following items from settings: \itemize{ \item settings$pfts \item settings$database$bety diff --git a/modules/meta.analysis/tests/testthat/test.jagify.R b/modules/meta.analysis/tests/testthat/test.jagify.R new file mode 100644 index 00000000000..50949a7a5d7 --- /dev/null +++ b/modules/meta.analysis/tests/testthat/test.jagify.R @@ -0,0 +1,23 @@ + +test_that("jagify correctly assigns treatment index of 1 to all control treatments, regardless of alphabetical order", { + ## generate test data; controls assigned to early alphabet and late alphabet trt names + testresult <- data.frame(citation_id = 1, + site_id = rep(1:2, each = 5), + name = rep(letters[1:5],2), + trt_id = as.character(rep(letters[1:5],2)), + control = c(1, rep(0,8), 1), + greenhouse = c(rep(0,5), rep(1,5)), + date = 1, + time = NA, + cultivar_id = 1, + specie_id = 1, + n = 2, + mean = sqrt(1:10), + stat = 1, + statname = "SE", + treatment_id = 1:10 + ) + + jagged.data <- jagify(testresult) + expect_equal(jagged.data$trt_num[jagged.data$trt == "control"], c(1, 1)) +}) diff --git a/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R b/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R index f777fdbd7e8..1f9c9c9a3fd 100644 --- a/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R +++ b/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R @@ -1,42 +1,33 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2012 University of Illinois, NCSA. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the -# University of Illinois/NCSA Open Source License -# which accompanies this distribution, and is available at -# http://opensource.ncsa.illinois.edu/license.html -#------------------------------------------------------------------------------- - -context("run.meta.analysis") - +test_that("`runModule.run.meta.analysis` throws an error for incorrect input", { + expect_error(runModule.run.meta.analysis('test'), "only works with Settings or MultiSettings") +}) -test_that("singleMA gives expected result for example inputs",{ - ## need to calculate x - ## x <- singleMA(....) - #expect_equal(round(summary(x)$statistics["beta.o", "Mean"]), 5) +test_that("`run.meta.analysis` able to call run.meta.analysis.pft for each pft in the input list", { + mocked_res <- mockery::mock(1, cycle = TRUE) + mockery::stub(run.meta.analysis, 'run.meta.analysis.pft', mocked_res) + mockery::stub(run.meta.analysis, 'PEcAn.DB::db.open', 1) + mockery::stub(run.meta.analysis, 'PEcAn.DB::db.close', 1) + pfts <- list('ebifarm.salix', 'temperate.coniferous') + run.meta.analysis(pfts = pfts, iterations = 1, dbfiles = NULL, database = NULL) + mockery::expect_called(mocked_res, 2) + args <- mockery::mock_args(mocked_res) + expect_equal(args[[1]][[1]], "ebifarm.salix") + expect_equal(args[[2]][[1]], "temperate.coniferous") }) -test_that("jagify correctly assigns treatment index of 1 to all control treatments, regardless of alphabetical order", { - ## generate test data; controls assigned to early alphabet and late alphabet trt names - testresult <- data.frame(citation_id = 1, - site_id = rep(1:2, each = 5), - name = rep(letters[1:5],2), - trt_id = as.character(rep(letters[1:5],2)), - control = c(1, rep(0,8), 1), - greenhouse = c(rep(0,5), rep(1,5)), - date = 1, - time = NA, - cultivar_id = 1, - specie_id = 1, - n = 2, - mean = sqrt(1:10), - stat = 1, - statname = "SE", - treatment_id = 1:10 +test_that("`run.meta.analysis.pft` throws an error if it cannot find output from get.trait", { + pft <- list(outdir = "", name = "ebifarm.salix") + expect_error( + run.meta.analysis.pft(pft = pft, iterations = 1, dbfiles = NULL, dbcon = NULL), + "Could not find output from get.trait" ) - i <- sapply(testresult, is.factor) - testresult[i] <- lapply(testresult[i], as.character) - - jagged.data <- jagify(testresult) - expect_equal(jagged.data$trt_num[jagged.data$trt == "control"], c(1, 1)) }) + +test_that("`run.meta.analysis.pft` throws an error for missing posteriorid", { + pft <- list(outdir = "test", name = "ebifarm.salix") + mockery::stub(run.meta.analysis.pft, 'file.exists', TRUE) + expect_error( + run.meta.analysis.pft(pft = pft, iterations = 1, dbfiles = NULL, dbcon = NULL, update = TRUE), + "Missing posteriorid" + ) +}) \ No newline at end of file