Commit 9b57a702 authored by Chris Jewell's avatar Chris Jewell
Browse files

Minor

parent 32eef4ee
......@@ -512,32 +512,20 @@ HaldDP <- R6::R6Class(
{
if (!is.data.frame(k))
stop("k must be a data frame.")
k <- na.omit(k)
if (!all(c("Value", "Source", "Time") %in% colnames(k)))
stop("k must have columns named Value, Source and Time.")
k$Source <- as.factor(k$Source)
k$Time <- as.factor(k$Time)
if (all(paste(gtools::mixedsort(unique(k$Time))) != private$namesTimes))
if (!setequal(unique(k$Time), private$namesTimes))
stop("The times in the Time column of k must be the same as those in the data.")
if (all(paste(gtools::mixedsort(unique(k$Source))) != private$namesSources))
if (!setequal(unique(k$Source), private$namesSources))
stop("The sources in the Source column of k must be the same as those in the data.")
if (dim(unique(k[, c("Time", "Source")]))[1] != (private$nTimes * private$nSources))
stop("k must have a single number for each time, source combination.")
## check all data values are positive, numeric, and whole numbers
if (!all(is.finite(k$Value)) |
!all(k$Value >= 0) | !all(k$Value <= 1))
stop("All prevalence values must be numbers between 0 and 1.")
private$k = tryCatch(
acast(k, Source ~ Time, value.var = 'Value'),
condition = function(c)
stop('Malformed k. Check Source/Time combinations for regularity.')
stop('k must have a single number for each time, source combination. Check Source/Time combinations for regularity.')
)
if (!all(is.finite(private$k) & private$k >=0 & private$k <=1))
stop("Prevalence value outside [0,1]. Check each Source/Time combination has a value.")
},
set_a_q = function(a_q)
{
......@@ -722,9 +710,9 @@ HaldDP <- R6::R6Class(
inits$r$Source <- as.factor(inits$r$Source)
inits$r$Time <- as.factor(inits$r$Time)
if (!all(paste(gtools::mixedsort(unique(inits$r$Type))) == private$namesTypes) |
!all(paste(gtools::mixedsort(unique(inits$r$Time))) == private$namesTimes) |
!all(paste(gtools::mixedsort(unique(inits$r$Source))) == private$namesSources) |
if (!setequal(unique(inits$r$Type), private$namesTypes) |
!setequal(unique(inits$r$Time), private$namesTimes) |
!setequal(unique(inits$r$Source), private$namesSources) |
dim(inits$r)[1] != (private$nTypes * private$nSources * private$nTimes))
stop(
"inits$r must be a data frame with columns called Type, Source, Time and Value with one row per combination of type, source and time."
......
Supports Markdown
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