Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Poppy Miller
sourceR
Commits
9b57a702
Commit
9b57a702
authored
Apr 10, 2017
by
Chris Jewell
Browse files
Minor
parent
32eef4ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/interface.R
View file @
9b57a702
...
...
@@ -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."
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment