stocnet / MoNAn

R package for the analysis of mobility networks
GNU General Public License v3.0
11 stars 0 forks source link

Clean up if conditions in error messages #19

Closed perblock closed 8 months ago

perblock commented 9 months ago

Found if() conditions comparing class() to string: File ‘MoNAn/R/1_hiddenFunctions.R’: if (!(class(state[[dep.var]]) == "edgelist.monan")) ... File ‘MoNAn/R/1_hiddenFunctions.R’: if (!(class(state[[nodesets[i]]]) == "nodeSet.monan")) ... File ‘MoNAn/R/1_hiddenFunctions.R’: if (!(class(state[[covars[i]]]) == "nodeVar.monan" || class(state[[covars[i]]]) == "network.monan")) ... Use inherits() (or maybe is()) instead.

perblock commented 9 months ago

Additionally, this throws an error, but should not: myState <- createProcessState( list( transfers = transfers, people = people, organisations = organisations), dependentVariable = "transfers")

perblock commented 9 months ago

And this gives an odd warning that disappears when the line with sex or with second_or is removed: myState <- createProcessState( list( transfers = transfers, people = people, organisations = organisations, sameRegion = sameRegion, region = region, size = size, sex = sex, second_or = second_or), dependentVariable = "transfers")

nikeis commented 8 months ago

Found if() conditions comparing class() to string: File ‘MoNAn/R/1_hiddenFunctions.R’: if (!(class(state[[dep.var]]) == "edgelist.monan")) ... File ‘MoNAn/R/1_hiddenFunctions.R’: if (!(class(state[[nodesets[i]]]) == "nodeSet.monan")) ... File ‘MoNAn/R/1_hiddenFunctions.R’: if (!(class(state[[covars[i]]]) == "nodeVar.monan" || class(state[[covars[i]]]) == "network.monan")) ... Use inherits() (or maybe is()) instead.

=> adjusted, uses inherits() now

nikeis commented 8 months ago

Additionally, this throws an error, but should not: myState <- createProcessState( list( transfers = transfers, people = people, organisations = organisations), dependentVariable = "transfers")

=> did throw an error because there were no covars in the example code, now covars are only checked if there actually are covars in the state object

nikeis commented 8 months ago

And this gives an odd warning that disappears when the line with sex or with second_or is removed: myState <- createProcessState( list( transfers = transfers, people = people, organisations = organisations, sameRegion = sameRegion, region = region, size = size, sex = sex, second_or = second_or), dependentVariable = "transfers")

=> problem was that sameRegion is assigned to the same nodeset (organisations) twice which results in a length of 2 => if this object of length two is compared ("==") to another object of a length which is not a multiple of 2, a warning is given => solved using "%in%" instead of "=="