marcpabst / ANOVA.jl

Provides a Simple Way to Calculate ANOVAs From Fitted Linear Models.
Other
21 stars 9 forks source link

Output of anova() prints twice at REPL #6

Closed BioTurboNick closed 1 year ago

BioTurboNick commented 5 years ago

The output of anova() at the REPL prints its output normally first, then repeats it after the Julia> prompt interrupting the first line. Typing at the prompt moves the prompt to the last line, overwriting it.

anova

This is in JuliaPro 1.0.1.1 with Julia 1.0.2

marcpabst commented 5 years ago

That's weird. I'm just using a simple DataFrame to print the AnovaObject:

function Base.show(io::IO, x::AnovaObject)
  print(DataFrame( 
          Source = x.Source,
          DF = x.DF,
          SS = x.SS,
          MSS = x.MSS,
          F = x.F,
          p = x.p
          ))
end

The only thing I can think of is that DataFrame itself creates the output. I currently don't have a Julia output installed but will look into it when I have more time. Thanks for the issue!

BioTurboNick commented 5 years ago

It's possible it's a more general issue with the REPL or Juno. For instance, I've noticed that when I return a plot from a function, it may render twice. I might poke around more.

marcpabst commented 5 years ago

Have you been able to solve your issue?

BioTurboNick commented 5 years ago

Yes, it appears that the issue is specific to the Juno REPL. It does not occur when Julia REPL is run in CMD.exe.

I'm closing this and I'll report it for Juno.

pfitzseb commented 5 years ago

Hm, the problem isn't really with Juno here but with your show method -- it's expected that you actually print something to io instead of stdout, i.e.

function Base.show(io::IO, x::AnovaObject)
  print(io, DataFrame( 
          Source = x.Source,
          DF = x.DF,
          SS = x.SS,
          MSS = x.MSS,
          F = x.F,
          p = x.p
          ))
end

I'm pretty confident that making this change will fix the weird behaviour in Juno/JuliaPro.

BioTurboNick commented 5 years ago

Ah. Why would the behavior differ between the two REPLs? (Actually, it's the same REPL though, just run inside Juno.)

pfitzseb commented 5 years ago

Not sure, tbh. I can't repro this when evaling in the REPL only. Can you try

struct Foo end

function Base.show(io::IO, x::Foo)
  print("hii")
  sleep(0.5)
  print("ho")
end

Foo()

in the REPL and in an editor for me?

BioTurboNick commented 5 years ago

In Juno:

julia> Foo()
hiihiiho

julia> ho

Where "ho" is just displayed at the prompt but not really there.

Edit: Second time I ran it, the last "ho" appeared before the prompt. Third time the last "ho" didn't appear at all.

show(stdout, Foo()) produces the correct output.

If I add a method without io::IO argument, show(Foo()) works, but Foo() alone still has the issue.

pfitzseb commented 5 years ago

Right, I can repro now. This only happens in JuliaPro and not in a standalone Juno install, probably be because the former is built with older releases.

struct Foo end

function Base.show(io::IO, x::Foo)
  print(io, "hii")
  sleep(0.5)
  print(io, "ho")
end

Foo()

works correctly for me in Juno, JuliaPro, and a standalone REPL. Can you confirm?

BioTurboNick commented 5 years ago

Confirmed. Thanks @pfitzseb . I'll grab standalone Juno.

pfitzseb commented 5 years ago

The show method should still be fixed in this package though, @marcpabst.

marcpabst commented 5 years ago

Thanks, @pfitzseb for exposing the problem! I'll make the change within the next few days!

Nosferican commented 5 years ago

Will be fixed as part of #10.