Commit 82c9d29f authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

Merge branch '49-fix-prepgr-when-the-dataset-is-format-as-a-tibble-object' into 'dev'

Resolve "Fix PrepGR when the dataset is format as a tibble object"

Closes #49

See merge request !25
parents a8dd6c45 6e951cbc
Pipeline #28233 passed with stage
in 1 minute and 25 seconds
......@@ -27,6 +27,7 @@ Suggests:
knitr,
rmarkdown,
testthat,
tibble,
htmlwidgets (>= 1.5.3)
Description: Add-on package to the 'airGR' package that simplifies its use and is aimed at being used for teaching hydrology. The package provides 1) three functions that allow to complete very simply a hydrological modelling exercise 2) plotting functions to help students to explore observed data and to interpret the results of calibration and simulation of the GR ('Génie rural') models 3) a 'Shiny' graphical interface that allows for displaying the impact of model parameters on hydrographs and models internal variables.
License: GPL-2
......
......@@ -12,7 +12,7 @@ PrepGR <- function(ObsDF = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Q
if (!is.null(ObsDF)) {
if (ncol(ObsDF) >= 5) {
TempMean <- ObsDF[, 5L]
TempMean <- ObsDF[, 5L, drop = TRUE]
}
}
......@@ -37,10 +37,10 @@ PrepGR <- function(ObsDF = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Q
}
if (!is.null(ObsDF)) {
ObsDF <- data.frame(DatesR = ObsDF[, 1L],
Precip = ObsDF[, 2L],
PotEvap = ObsDF[, 3L],
Qobs = ObsDF[, 4L],
ObsDF <- data.frame(DatesR = ObsDF[, 1L, drop = TRUE],
Precip = ObsDF[, 2L, drop = TRUE],
PotEvap = ObsDF[, 3L, drop = TRUE],
Qobs = ObsDF[, 4L, drop = TRUE],
TempMean = TempMean)
}
......
context("PrepGR")
# --------
library(tibble)
# --------
data(L0123001, package = "airGR")
BasinObs <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
BasinObs2 <- BasinObs
colnames(BasinObs2) <- letters[seq_along(colnames(BasinObs2))]
# --------
test_that("ObsDF with custom column names", {
expect_equal(
object = PrepGR(ObsDF = BasinObs, HydroModel = "GR4J", CemaNeige = FALSE)
,
expected = PrepGR(ObsDF = BasinObs2, HydroModel = "GR4J", CemaNeige = FALSE),
)
})
# ----
test_that("ObsDF is a tibble data.frame", {
expect_equal(
object = PrepGR(ObsDF = BasinObs, HydroModel = "GR4J", CemaNeige = FALSE)
,
expected = PrepGR(ObsDF = as_tibble(BasinObs), HydroModel = "GR4J", CemaNeige = FALSE),
)
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment