I am trying to use the package 'assertive'. I managed to make it work in this simple case:
foo <- function(x) {
assertive::is_positive(x)
}
foo(-1)
# There was 1 failure:
# Position Value Cause
# 1 1 -1 too low
However, in a more complicated function it has no effect. I show only the beginning of the function, as it has many lines.
model.optimize <- function(model_info,
data,
n.best=1L,
dt.intvl=NULL,
stat="Sharpe_Ratio",
stats.list=stats.list,
min.length=-1L,
n.cores=1L) {
assertive::is_positive(-1L)
# many lines of code
Here is the result or running 'model.optimize':
> model.optimize(model_info,
+ df_all_data,
+ n.best=n.best,
+ dt.intvl=dt.intvl,
+ stat=statistic,
+ stats.list=stats.list,
+ min.length=-1L,
+ n.cores=n.model.cores) -> mo
Optimizing Model
Number of Iterations: 1
Number of Cores: 1
Optimization executed in: 2.23 secs
The command 'is_positive' had no effect!
If I wrap 'print' around the assertion, like this:
print(is_positive(-1))
then I get the correct warning.
Any tips on why does 'is_positive' work in one case and not in the other?