Skip to content

Recurrent warning messages related to MigClim.migrate() barrier type and barrier arguments #2

@pedrohbraga

Description

@pedrohbraga

Hi, Robin

I understand that the package is a little outdated and that you mentioned wanting to do a few updates on it in the future. I am going to post here a few issues I have been coming when using MigClim.

I have been able to install the MigClim library directly from this repository using devtools::install_github:

devtools::install_github("jjvanderwal/SDMTools")
devtools::install_github("robinengler/MigClim")

library(MigClim)

The package loaded without issues. Nevertheless, I have been getting recurrent warning messages related to the type of barrier and the 'iniDist' and 'barrier' arguments and objects. This happens using my own data, but also with the test data provided by the package. See an example below:

data(MigClim.testData)

### Run MigClim with a data frame type input.
n <- MigClim.migrate(iniDist = MigClim.testData[,1:3],
                    hsMap = MigClim.testData[,4:8], 
                    rcThreshold = 500, 
                    envChgSteps = 5, 
                    dispSteps =5, 
                    dispKernel = c(1.0, 0.4, 0.16, 0.06, 0.03),
                    barrier = MigClim.testData[,9], 
                    barrierType='strong', 
                    iniMatAge=1, 
                    propaguleProd=c(0.01, 0.08, 0.5, 0.92),
                    lddFreq = 0.1, 
                    lddMinDist = 6, 
                    lddMaxDist = 15, 
                    simulName = "MigClimTest", 
                    replicateNb = 1, 
                    overWrite = TRUE, 
                    testMode = FALSE, 
                    fullOutput = TRUE, 
                    keepTempFiles = TRUE)

Output:

Warning messages:
1: In if (barrier != "") if (!any(barrierType == c("weak", "strong"))) stop("'barrierType' must be either 'weak' or 'strong'. \n") :
  the condition has length > 1 and only the first element will be used
2: In if (barrier != "") if (is.character(barrier)) stop("Data input error: 'iniDist' and 'barrier' must have the same format: either both 'string' or both 'data frame/matrix/vector'. \n") :
  the condition has length > 1 and only the first element will be used

I have gone through a bit of the code and I have realized that the error is happening because the if (barrier != ""), located in multiple instances within the MigClim.migrate function gets conflicted when an object with more than one element is provided to it.

I have found that the error disappears and that the function performs correctly if we replace if (barrier != "") by if (!identical(barrier, "")), which I believe does the test you intended.

I am going to double-check this later on and, if it helps, I will try to produce a pull request if everything works well!

Best regards,
Pedro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions