PredictiveEcology / LandR

Landscape Ecosystem Modelling in R
https://landr.predictiveecology.org/
GNU General Public License v3.0
17 stars 7 forks source link

bug in dropTerm #105

Open CeresBarros opened 4 months ago

CeresBarros commented 4 months ago

reprex

repos <- c("predictiveecology.r-universe.dev", getOption("repos"))
install.packages(c("LandR"), repos = repos)
library(LandR)

dropTerm("B ~ logAge * speciesCode + cover * speciesCode + (logAge + cover + speciesCode | ecoregionGroup)", c("speciesCode"))
# Error in str2lang(x) : <text>:2:0: unexpected end of input
# 1: . ~ . -
#   ^
dropTerm("B ~ logAge * speciesCode + cover * speciesCode + (logAge + cover + speciesCode | ecoregionGroup)", c("cover"))
# Error in str2lang(x) : <text>:2:0: unexpected end of input
# 1: . ~ . -
#   ^
CeresBarros commented 4 months ago

I've tracked this down to a bad subsetting of the fac matrix, which results in an empty toDrop object.

However, there's another deeper problem. Even after making sure that the formula terms where speciesCode and cover appear are correctly identified, the way the function is written results in completely dropping (logAge + cover + speciesCode | ecoregionGroup), instead of keeping (logAge | ecoregionGroup)...

CeresBarros commented 4 months ago

@achubaty @ianmseddy @eliotmcintire I'm worried about this and I can't find a good way of fixing the issue. So more eyes would be appreciated