diff --git a/tests/testthat/helper_vignettes.R b/tests/testthat/helper_vignettes.R index 81009d9311a74da6352212649f8579f2b95319c6..0d274587d34363f2bbedaa1b7f43394045afd19a 100644 --- a/tests/testthat/helper_vignettes.R +++ b/tests/testthat/helper_vignettes.R @@ -5,7 +5,7 @@ #' @param force.eval Force execution of chunks with parameter eval=FALSE RunRmdChunks <- function(fileRmd, tmpFolder = "../tmp", - force.eval = FALSE) { + force.eval = TRUE) { dir.create(tmpFolder, showWarnings = FALSE) output = file.path(tmpFolder, gsub("\\.Rmd", "\\.R", basename(fileRmd), ignore.case = TRUE)) @@ -34,7 +34,7 @@ RunRmdChunks <- function(fileRmd, x = sTxt[chunksEvalStart[i]:chunksEvalEnd[i]]) } } - + } # Remove line of code displaying data removeFromGrep <- function(pattern, x) { @@ -52,7 +52,7 @@ RunRmdChunks <- function(fileRmd, exLines = grep("^example\\(.*\\)", sTxt) sTxt[exLines] = paste0(substr(sTxt[exLines], 1, nchar(sTxt[exLines]) - 1), ", local = TRUE, echo = FALSE, verbose = FALSE, ask = FALSE)") # Remove question "Hit <Return> to see next plot" - sTxt = c("par(ask=F)", sTxt) + sTxt = c("par(ask=F)", sTxt) # Write the transformed script writeLines(sTxt, output) # Silently run the chunks diff --git a/tests/testthat/test-vignettes.R b/tests/testthat/test-vignettes.R index c6eb47a1270bed81ff32642bfbe114b133d3ddf0..93b51d3d8e7a105a8f3cfdd6f2ae012d2e955a93 100644 --- a/tests/testthat/test-vignettes.R +++ b/tests/testthat/test-vignettes.R @@ -1,26 +1,41 @@ context("Test vignette chunks") test_that("V01_get_started works", { + skip_on_cran() + rm(list=ls()) RunRmdChunks("../../vignettes/V01_get_started.Rmd") - + # Test Qmm -> Qls conversion in input + notNA = which(!is.na(BasinObs$Qmm)) + expect( + all(abs(BasinObs$Qmm[notNA] * BasinInfo$BasinArea / 86400 * 1E6 - BasinObs$Qls[notNA]) < 1E-7), + "Error in conversion Qmm -> Qls" + ) }) test_that("V02.1_param_optim works", { - RunRmdChunks("../../vignettes/V02.1_param_optim.Rmd", force.eval = TRUE) - + skip_on_cran() + skip("hydroPSO not working presently") + rm(list=ls()) + RunRmdChunks("../../vignettes/V02.1_param_optim.Rmd") }) test_that("V02.2_param_mcmc works", { - RunRmdChunks("../../vignettes/V02.2_param_mcmc.Rmd", force.eval = TRUE) - + skip_on_cran() + rm(list=ls()) + RunRmdChunks("../../vignettes/V02.2_param_mcmc.Rmd") + }) test_that("V03_param_sets_GR4J works", { - RunRmdChunks("../../vignettes/V03_param_sets_GR4J.Rmd", force.eval = TRUE) - + skip_on_cran() + rm(list=ls()) + RunRmdChunks("../../vignettes/V03_param_sets_GR4J.Rmd") + }) test_that("V04_cemaneige_hysteresis works", { - RunRmdChunks("../../vignettes/V04_cemaneige_hysteresis.Rmd", force.eval = TRUE) - + skip_on_cran() + rm(list=ls()) + RunRmdChunks("../../vignettes/V04_cemaneige_hysteresis.Rmd") + }) diff --git a/vignettes/V02.2_param_mcmc.Rmd b/vignettes/V02.2_param_mcmc.Rmd index 4555cf0c7f0a0d7bc42ecbfa634d6379ce11b95f..391e315b1d5645f1df09d01dbb5450df931907ff 100644 --- a/vignettes/V02.2_param_mcmc.Rmd +++ b/vignettes/V02.2_param_mcmc.Rmd @@ -48,8 +48,8 @@ Please note that this vignette is only for illustration purposes and does not pr We show how to use the DRAM algorithm for SLS Bayesian inference, with the `modMCMC()` function of the [FME](https://cran.r-project.org/package=FME) package. First, we need to define a function that returns twice the opposite of the log-likelihood for a given parameter set. -Nota: in the `LogLikeGR4J()` function, the computation of the log-likelihood is simplified in order to ensure a good computing performance. It corresponds to a translation of the two following lines. -```{r, echo=TRUE, eval=FALSE} +Nota: in the `LogLikeGR4J()` function, the computation of the log-likelihood is simplified in order to ensure a good computing performance. It corresponds to a translation of the two following lines. +```{r, echo=TRUE, eval=FALSE, purl=FALSE} Likelihood <- sum((ObsY - ModY)^2, na.rm = TRUE)^(-sum(!is.na(ObsY)) / 2) LogLike <- -2 * log(Likelihood) ``` @@ -79,7 +79,7 @@ LogLikeGR4J <- function(ParamOptim) { ## Estimation of the best-fit parameters as a starting point We start by using the PORT optimization routine to estimate the best-fit parameters. ```{r, results='hide', eval=FALSE} -optPORT <- stats::nlminb(start = c(4.1, 3.9, -0.9, -8.7), +optPORT <- stats::nlminb(start = c(4.1, 3.9, -0.9, -8.7), objective = LogLikeGR4J, lower = rep(-9.9, times = 4), upper = rep(9.9, times = 4), control = list(trace = 1))