Skip to content

Commit

Permalink
better error catch for bad arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Dec 11, 2024
1 parent 5f95ff2 commit 9593da1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pomp
Type: Package
Title: Statistical Inference for Partially Observed Markov Processes
Version: 6.0.1.0
Date: 2024-12-08
Version: 6.0.1.1
Date: 2024-12-11
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")),
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
person(given="Carles",family="Bretó",role="aut",comment=c(ORCID="0000-0003-4695-4902")),
Expand Down
30 changes: 17 additions & 13 deletions R/pomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,27 @@ pomp <- function (
)
return(as(data,"pomp"))

extra_args <- list(...)
if (length(extra_args)>0L) {
nm <- names(extra_args)
if (length(nm)==0 || any(nchar(nm)==0))
pStop_("Unnamed arguments are not permitted.")
else
pStop_("The ",
ngettext(length(extra_args),"argument ","arguments "),
paste(sQuote(nm),collapse=","),
ngettext(length(extra_args)," is"," are"),
" not recognized.\nUse the ",sQuote("userdata"),
" argument to supply extra objects to basic model components.\n",
"See ",sQuote("?userdata"),"."
)
}

if (missing(times)) times <- NULL

tryCatch(
construct_pomp(
data=data,times=times,t0=t0,...,
data=data,times=times,t0=t0,
rinit=rinit,dinit=dinit,
rprocess=rprocess,dprocess=dprocess,
rmeasure=rmeasure,dmeasure=dmeasure,
Expand Down Expand Up @@ -450,7 +466,6 @@ setMethod(

pomp_internal <- function (
data,
...,
times, t0, timename,
rinit, dinit, rprocess, dprocess,
rmeasure, dmeasure, emeasure, vmeasure,
Expand Down Expand Up @@ -482,17 +497,6 @@ pomp_internal <- function (
else
timename <- as.character(timename)

added.userdata <- list(...)
if (length(added.userdata)>0L) {
pStop_("The ",
ngettext(length(added.userdata),"argument","arguments")," ",
paste(sQuote(names(added.userdata)),collapse=","),
ngettext(length(added.userdata),"is","are"),
" not recognized.\nUse the ",sQuote("userdata"),
" argument to supply extra objects to basic model components.",
" See ",sQuote("?userdata"),"."
)
}
.userdata[names(userdata)] <- userdata

if (!is(rprocess,"rprocPlugin")) {
Expand Down
3 changes: 1 addition & 2 deletions tests/issue222.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ Error : in 'simulate': argument is missing, with no default
+ )
+ )
+ )
Error : in 'simulate': The argument is not recognized.
Use the 'userdata' argument to supply extra objects to basic model components. See '?userdata'.
Error : in 'simulate': Unnamed arguments are not permitted.
>
> dev.off()
null device
Expand Down
4 changes: 2 additions & 2 deletions tests/kalman.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Error : in 'enkf': 'Np' should be a single positive integer.
> try(enkf(pf,Np="10b"))
Error : in 'enkf': 'Np' should be a single positive integer.
In addition: Warning message:
In enkf_internal(data, Np = Np, ..., verbose = verbose) :
In enkf_internal(data, ..., Np = Np, verbose = verbose) :
NAs introduced by coercion
> try(enkf(pf,Np=100,emeasure=NULL))
Error : in 'enkf': 'emeasure' is a needed basic component.
Expand Down Expand Up @@ -164,7 +164,7 @@ Error : in 'eakf': 'Np' should be a single positive integer.
> try(eakf(enkf,Np="10b"))
Error : in 'eakf': 'Np' should be a single positive integer.
In addition: Warning message:
In eakf_internal(data, Np = Np, ..., verbose = verbose) :
In eakf_internal(data, ..., Np = Np, verbose = verbose) :
NAs introduced by coercion
> try(eakf(enkf,Np=100,emeasure=NULL))
Error : in 'eakf': 'emeasure' is a needed basic component.
Expand Down
5 changes: 3 additions & 2 deletions tests/mif2.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ loglik: NA
+ drpocess="oops",
+ dmeasure=function(log,...)0) -> mf3
+ )
Error : in 'mif2': The argument 'drpocess'is not recognized.
Use the 'userdata' argument to supply extra objects to basic model components. See '?userdata'.
Error : in 'mif2': The argument 'drpocess' is not recognized.
Use the 'userdata' argument to supply extra objects to basic model components.
See '?userdata'.
> mif2(po,Nmif=2,Np=50,rw.sd=rw_sd(sigma=0.01),
+ cooling.type="hyper",cooling.fraction.50=0.1,
+ dmeasure=function(log,...)0) -> mf3
Expand Down
4 changes: 4 additions & 0 deletions tests/userdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ try(po |>
SEXP Msg = get_userdata("bob");
char *msg = CHAR(STRING_ELT(Msg,0));
Rprintf("%s\n",msg);}"))))
try(po |> simulate(time=1:3))
try(po |> simulate(time=1:3,bob=77))
try(po |> simulate(times=1:3,seed=NULL,nsim=5,77))
try(po |> pomp(77))
try(po |>
simulate(rprocess=onestep(
Csnippet(r"{double nbasis = *(get_userdata_double("nbasis"));}"))))
Expand Down
12 changes: 12 additions & 0 deletions tests/userdata.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ hello!
+ char *msg = CHAR(STRING_ELT(Msg,0));
+ Rprintf("%s\n",msg);}"))))
Error : in 'simulate': no user-data element 'bob' is found.
> try(po |> simulate(time=1:3))
Error : in 'simulate': The argument 'time' is not recognized.
Use the 'userdata' argument to supply extra objects to basic model components.
See '?userdata'.
> try(po |> simulate(time=1:3,bob=77))
Error : in 'simulate': The arguments 'time','bob' are not recognized.
Use the 'userdata' argument to supply extra objects to basic model components.
See '?userdata'.
> try(po |> simulate(times=1:3,seed=NULL,nsim=5,77))
Error : in 'simulate': Unnamed arguments are not permitted.
> try(po |> pomp(77))
Error : Unnamed arguments are not permitted.
> try(po |>
+ simulate(rprocess=onestep(
+ Csnippet(r"{double nbasis = *(get_userdata_double("nbasis"));}"))))
Expand Down

0 comments on commit 9593da1

Please sign in to comment.