PhilipMostert / PointedSDMs

Wrapper function for 'inlabru' for modeling species distribution models from disparate datasets.
23 stars 2 forks source link

updateFormula() checks length of datasetName incorrectly #11

Closed oharar closed 5 months ago

oharar commented 5 months ago

I just got this error:

initMod$updateFormula(datasetName = PA.spat, Formula = ~ . - A) Error in initMod$updateFormula(datasetName = PA.spat, Formula = ~. - : Please only provide one dataset name.

The problem is that PA.spat is a data frame, and on l1065 of dataSDM.R the test is:

if (length(datasetName) != 1) stop ('Please only provide one dataset name.')

I think the solutiuon is to use sys.call() From

Z <- 1:10 tmpfun <- function(x,y,z,...) { length(as.list( sys.call() )$z) } tmpfun( x=5, w=3, z=Z )

(adapted from Greg Snow's explanation here: https://stat.ethz.ch/pipermail/r-help/2011-September/288786.html)

Without testing, I think this should work: if (length(as.list(sys.call())$datasetName) != 1) stop ('Please only provide one dataset name.')

which does look ugly

PhilipMostert commented 5 months ago

Hi Bob,

The datasetName argument needs to be a character of one of the dataset's names added in intModel. I'll change some of the documentation and add some more defences to ensure that that is the case before it hits that error.

oharar commented 5 months ago

Ah, that works! :-)