bbolker / broom.mixed

tidy methods for mixed models in R
227 stars 23 forks source link

Fix issue with underscores in terms for brms models / ran_vals #80

Closed sam-crawley closed 4 years ago

sam-crawley commented 4 years ago

For brms models, if a term had an underscore in it, the string splitting got confused for ran_vals.

e.g.

data("sleepstudy")
sleepstudy$Days_extra <- sleepstudy$Days
model.brms <- brm(Reaction ~ Days_extra + (Days_extra|Subject), sleepstudy, chains = 2)
tidy(model.brms, effect = "ran_vals")

This would result in "Days" getting added to the levels column, and "extra" in the term column.

This commit fixes this by replacing strsplit with a regex using str_match_all.

bbolker commented 4 years ago

thanks! I'm hoping I (or you) can modify the existing tests so that they check for this issue (i.e. regression tests). May pull this first anyway ...

sam-crawley commented 4 years ago

Yes, I'll add a test shortly.

bbolker commented 4 years ago

also, looks (based on TravisCI) as though this fails the test here?

sam-crawley commented 4 years ago

Should be good now.