-1

I've got a very strange problem in R. I'm trying to run a plm with a certain panel data.frame. If i run the model, sometimes there's warning and sometimes there isn't. How is that possible? If i type class(mydf), exactly the same thing, only sometimes a warning. Does anyone know what this is about?

class(mydf)
[1] "data.frame"
Warning messages:
1: In if (is.na(le)) { :
  the condition has length > 1 and only the first element will be used
2: In if (is.na(le)) " __no length(.)__ " else if (give.length) { :
  the condition has length > 1 and only the first element will be used
3: In if (le > 0) paste0("[1:", paste(le), "]") else "(0)" :
  the condition has length > 1 and only the first element will be used
class(mydf)
[1] "data.frame"
cptn
  • 693
  • 2
  • 8
  • 28

2 Answers2

1

I don't think the cited page explains why this is happening at all. There is a bug somewhere. The code should be tracked down and the offending lines fixed:

if (is.na(le)) " __no length(.)__ " else if (give.length) { 

.... should be changed to:

if ( all(is.na(le)) ) " __no length(.)__ " else if (give.length) { 

I agree with Paul that you should make this reproducible.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
0

This is because str checks the length of its object and some objects, say the extended formulas from the Formula package does not have a single length. In particular, Formula:::length.Formula returns a vector rather than a number, which causes the warning. While you may not call str yourself, perhaps your IDE, say RStudio, may use it to show the object structure of objects in the workspace.

Stefan
  • 1,835
  • 13
  • 20