Skip to content

Commit 9593da1

Browse files
committed
better error catch for bad arguments
1 parent 5f95ff2 commit 9593da1

7 files changed

+41
-21
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: pomp
22
Type: Package
33
Title: Statistical Inference for Partially Observed Markov Processes
4-
Version: 6.0.1.0
5-
Date: 2024-12-08
4+
Version: 6.0.1.1
5+
Date: 2024-12-11
66
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu",comment=c(ORCID="0000-0001-6159-3207")),
77
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
88
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),

R/pomp.R

+17-13
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,27 @@ pomp <- function (
187187
)
188188
return(as(data,"pomp"))
189189

190+
extra_args <- list(...)
191+
if (length(extra_args)>0L) {
192+
nm <- names(extra_args)
193+
if (length(nm)==0 || any(nchar(nm)==0))
194+
pStop_("Unnamed arguments are not permitted.")
195+
else
196+
pStop_("The ",
197+
ngettext(length(extra_args),"argument ","arguments "),
198+
paste(sQuote(nm),collapse=","),
199+
ngettext(length(extra_args)," is"," are"),
200+
" not recognized.\nUse the ",sQuote("userdata"),
201+
" argument to supply extra objects to basic model components.\n",
202+
"See ",sQuote("?userdata"),"."
203+
)
204+
}
205+
190206
if (missing(times)) times <- NULL
191207

192208
tryCatch(
193209
construct_pomp(
194-
data=data,times=times,t0=t0,...,
210+
data=data,times=times,t0=t0,
195211
rinit=rinit,dinit=dinit,
196212
rprocess=rprocess,dprocess=dprocess,
197213
rmeasure=rmeasure,dmeasure=dmeasure,
@@ -450,7 +466,6 @@ setMethod(
450466

451467
pomp_internal <- function (
452468
data,
453-
...,
454469
times, t0, timename,
455470
rinit, dinit, rprocess, dprocess,
456471
rmeasure, dmeasure, emeasure, vmeasure,
@@ -482,17 +497,6 @@ pomp_internal <- function (
482497
else
483498
timename <- as.character(timename)
484499

485-
added.userdata <- list(...)
486-
if (length(added.userdata)>0L) {
487-
pStop_("The ",
488-
ngettext(length(added.userdata),"argument","arguments")," ",
489-
paste(sQuote(names(added.userdata)),collapse=","),
490-
ngettext(length(added.userdata),"is","are"),
491-
" not recognized.\nUse the ",sQuote("userdata"),
492-
" argument to supply extra objects to basic model components.",
493-
" See ",sQuote("?userdata"),"."
494-
)
495-
}
496500
.userdata[names(userdata)] <- userdata
497501

498502
if (!is(rprocess,"rprocPlugin")) {

tests/issue222.Rout.save

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ Error : in 'simulate': argument is missing, with no default
103103
+ )
104104
+ )
105105
+ )
106-
Error : in 'simulate': The argument is not recognized.
107-
Use the 'userdata' argument to supply extra objects to basic model components. See '?userdata'.
106+
Error : in 'simulate': Unnamed arguments are not permitted.
108107
>
109108
> dev.off()
110109
null device

tests/kalman.Rout.save

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Error : in 'enkf': 'Np' should be a single positive integer.
134134
> try(enkf(pf,Np="10b"))
135135
Error : in 'enkf': 'Np' should be a single positive integer.
136136
In addition: Warning message:
137-
In enkf_internal(data, Np = Np, ..., verbose = verbose) :
137+
In enkf_internal(data, ..., Np = Np, verbose = verbose) :
138138
NAs introduced by coercion
139139
> try(enkf(pf,Np=100,emeasure=NULL))
140140
Error : in 'enkf': 'emeasure' is a needed basic component.
@@ -164,7 +164,7 @@ Error : in 'eakf': 'Np' should be a single positive integer.
164164
> try(eakf(enkf,Np="10b"))
165165
Error : in 'eakf': 'Np' should be a single positive integer.
166166
In addition: Warning message:
167-
In eakf_internal(data, Np = Np, ..., verbose = verbose) :
167+
In eakf_internal(data, ..., Np = Np, verbose = verbose) :
168168
NAs introduced by coercion
169169
> try(eakf(enkf,Np=100,emeasure=NULL))
170170
Error : in 'eakf': 'emeasure' is a needed basic component.

tests/mif2.Rout.save

+3-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ loglik: NA
185185
+ drpocess="oops",
186186
+ dmeasure=function(log,...)0) -> mf3
187187
+ )
188-
Error : in 'mif2': The argument 'drpocess'is not recognized.
189-
Use the 'userdata' argument to supply extra objects to basic model components. See '?userdata'.
188+
Error : in 'mif2': The argument 'drpocess' is not recognized.
189+
Use the 'userdata' argument to supply extra objects to basic model components.
190+
See '?userdata'.
190191
> mif2(po,Nmif=2,Np=50,rw.sd=rw_sd(sigma=0.01),
191192
+ cooling.type="hyper",cooling.fraction.50=0.1,
192193
+ dmeasure=function(log,...)0) -> mf3

tests/userdata.R

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ try(po |>
3939
SEXP Msg = get_userdata("bob");
4040
char *msg = CHAR(STRING_ELT(Msg,0));
4141
Rprintf("%s\n",msg);}"))))
42+
try(po |> simulate(time=1:3))
43+
try(po |> simulate(time=1:3,bob=77))
44+
try(po |> simulate(times=1:3,seed=NULL,nsim=5,77))
45+
try(po |> pomp(77))
4246
try(po |>
4347
simulate(rprocess=onestep(
4448
Csnippet(r"{double nbasis = *(get_userdata_double("nbasis"));}"))))

tests/userdata.Rout.save

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ hello!
6060
+ char *msg = CHAR(STRING_ELT(Msg,0));
6161
+ Rprintf("%s\n",msg);}"))))
6262
Error : in 'simulate': no user-data element 'bob' is found.
63+
> try(po |> simulate(time=1:3))
64+
Error : in 'simulate': The argument 'time' is not recognized.
65+
Use the 'userdata' argument to supply extra objects to basic model components.
66+
See '?userdata'.
67+
> try(po |> simulate(time=1:3,bob=77))
68+
Error : in 'simulate': The arguments 'time','bob' are not recognized.
69+
Use the 'userdata' argument to supply extra objects to basic model components.
70+
See '?userdata'.
71+
> try(po |> simulate(times=1:3,seed=NULL,nsim=5,77))
72+
Error : in 'simulate': Unnamed arguments are not permitted.
73+
> try(po |> pomp(77))
74+
Error : Unnamed arguments are not permitted.
6375
> try(po |>
6476
+ simulate(rprocess=onestep(
6577
+ Csnippet(r"{double nbasis = *(get_userdata_double("nbasis"));}"))))

0 commit comments

Comments
 (0)