decisionpatterns / formula.tools

Utilities for working with formulas, expressions, calls and other R objects
Other
17 stars 2 forks source link

formula.tools breaks lmerTest difflsmeans #7

Closed puterleat closed 6 years ago

puterleat commented 8 years ago

I'm not sure why this happens, but this throws an error only if the formula.tools package is loaded. I'm guessing it must be a bug in formula.tools:

library(formula.tools)
library(lmerTest)
m1 <- lmer(Informed.liking ~ Gender*Information +(1|Consumer), data=ham)
difflsmeans(m1, test.effs="Gender:Information")
puterleat commented 8 years ago

Sorry - should have added, the error is:

Error in parse(text = x, keep.source = FALSE) : 
  <text>:1:4: unexpected symbol
1: NA Informed.liking
       ^

And traceback():

14: parse(text = x, keep.source = FALSE)
13: eval(parse(text = x, keep.source = FALSE)[[1L]])
12: formula(eval(parse(text = x, keep.source = FALSE)[[1L]]))
11: formula.character(object, env = baseenv())
10: formula(object, env = baseenv())
9: as.formula(new)
8: update.formula(fmodel, model.red)

7: update(fmodel, model.red)
6: update(fmodel, model.red)
5: getFormula(obj, withRand = FALSE)
4: refitLM(rho$model)
3: calcLSMEANS(rho, alpha, test.effs, lsmeansORdiff, pdf)
2: lsmeans.calc(model, 0.05, test.effs = test.effs, lsmeansORdiff = FALSE, 
       pdf)
1: difflsmeans(m1, test.effs = "Gender:Information")
ctbrown commented 8 years ago

Curious. Thanks for the bug report.

C-

ctbrown commented 7 years ago

This has to do with lmerTest:::getFormula use of paste on a formula object which calls as.character. lmerTest relies on the as.character.default which produces a character vector of its arguments

On the other hand, formula.tools defines a specific user-friendly version of as.character.formula to provide a well-formatted object..

This is not really a problem with formula.tools. It is playing nicely. A probable solution is to change as.character.formula to as.string.formula.

ctbrown commented 7 years ago

It seems like there should be a specific string class for use here. A little looking would seem to indicate no package that provides a string class, except for the NLP package. (NB. stringr really isn't about strings at all.)