amvillegas / StMoMo

Stochastic Mortality Modelling
22 stars 6 forks source link

The use of Imports/Depends #18

Open mpascariu opened 6 years ago

mpascariu commented 6 years ago

StMoMo uses methods from gnm and forecast packages. In DESCRIPTION these are listed in Depends. This is not recommended and can cause problems. See a brief explanation here: https://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends

Practical examples:

> # Thu Aug  9 13:08:01 2018 ------------------------------
> library(StMoMo)
Loading required package: gnm
Loading required package: forecast

> # Example 1 -  OK
> LCfit <- fit(lc(), data = EWMaleData, ages.fit = 55:89)
StMoMo: Start fitting with gnm
Initialising
Running start-up iterations..
Running main iterations.....
Done
StMoMo: Finish fitting with gnm

> # Example 2 - Not OK
> Mult <- function(x) 1:x
> LCfit2 <- fit(lc(), data = EWMaleData, ages.fit = 55:89)
Error in model.frame.default(formula = D ~ factor(x) + Mult(factor(x),  : 
  invalid type (list) for variable 'Mult(factor(x), factor(t), inst = 1)'

The 2 examples are identical, we are just fitting a LC model (same data, same code). The first one works because it runs in a clean environment. The second one returns an error because at some point earlier I defined a function that (intentionally or not) has the same name as a function from gnm (a package that StMoMo depends on).

Solution: move all packages in Imports.

Or is there any reason these must be in Depends?