0

What does this error mean?

Error: rhs must be a language object

I can't really show you my text file associated with the code, but here is what got me the error if it helps:

t.test(BILL1~SEX, Credit, conf.level=0.95,
 mu = 0, paired=F,alternative = "two.sided",var.equal=F)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Laura
  • 19
  • 3
  • 1
    The right hand side of something must be a part of the language. – Eli Sadoff Nov 03 '16 at 23:18
  • what would make it not part of the language...? It's all numeric – Laura Nov 03 '16 at 23:21
  • 4
    Please add data to make your example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). If you can't show the real data, try making up some similar data that reproduces the problem. – aosmith Nov 03 '16 at 23:23

1 Answers1

3

tl;dr the mosaic::t.test function is not handling a second unnamed argument as one might expect based on stats::t.test ...

My Google search for the error message shows that this error only shows up in the lazyeval and mosaic packages. Further poking around shows that the mosaic package has a t.test() function that masks the stats::t.test() function that occurs in base R.

So the issue is very likely to be with that function, but without more information we can only speculate. I've tried various ways to break mosaic::t.test() (using variable names that aren't found in the data, using symbols that correspond to functions instead of data objects, etc. etc.), but can't provoke that error. Can you at the very least edit your question to include the results of str(Credit) ... ??

OK, I managed to guess it, and it's not actually anything wrong with your data (I think).

dd <- data.frame(x=1:10,y=rep(0:1,each=5))
stats::t.test(x~y,dd)   ## works fine
library(mosaic)
mosaic::t.test(x~y,Credit)
## Error: `rhs` must be a language object

Now the only change we make is to name the data= argument*:

mosaic::t.test(x~y,data=Credit)  ## works fine

The problem is that the definition of stats::t.test is

t.test(formula, data, subset, na.action, ...)

while that of mosaic::t.test is

 t.test(x, y=NULL, ..., data = parent.frame())

so that mosaic::t.test interprets the second argument, if it is unnamed, as a formula ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thanks to much adding str(Credit) worked! Sorry about not putting in the data I'm really new to R and coding in general and this was my first time using stackoverflow. Thanks again \ – Laura Nov 03 '16 at 23:31
  • ?? What does that mean ?? did using `str(Credit)` give you a clue about what was wrong that led you to solve your own problem? If so, you can (and are encouraged to) post an answer to your own question. (Now I really want to know what was going on ...) – Ben Bolker Nov 03 '16 at 23:32