fslaborg / RProvider

Access R packages from F#
http://fslab.org/RProvider/
Other
235 stars 69 forks source link

ggplot2 fails with RProvider #161

Closed evelinag closed 8 years ago

evelinag commented 8 years ago

I was using ggplot2 from RProvider, but it stopped working from RProvider version 1.1.12. Ggplot normally composes plots by adding layers and the resulting plot needs to be evaluated as a whole. Currently, each layer is evaluated immediately which leads to no layers in plot errors.

Code to reproduce the error:

open RProvider
open RProvider.graphics
open RProvider.ggplot2
open RProvider.datasets

let (++) (plot1:RDotNet.SymbolicExpression) (plot2:RDotNet.SymbolicExpression) =
    R.``+``(plot1, plot2)

fsi.AddPrinter(fun (synexpr:RDotNet.SymbolicExpression) ->
    synexpr.Print())

let mtc = R.mtcars
R.assign("mtc", mtc)
R.eval(R.parse(text = "library(ggplot2)"))

// fails because the first call to ggplot is evaluated individually
R.eval(R.parse(text = "ggplot(mtc, aes(x=disp, y=drat))")) ++ R.geom__point()

The code worked in RProvider 1.1.8.

tpetricek commented 8 years ago

I had a look at this and it seems to be caused by the fact that R.NET now automatically prints the results of expressions evaluated (this change sets AutoPrint to true). AFAIK this has no effect on R provider, because we are not capturing the automatic print output.

The reason why this breaks the above code is that R tries to show the incomplete chart created by the first part of the expression (before the ++). I think we can safely set AutoPrint = false in R provider because our F# Interactive load script prints things explicitly.

evelinag commented 8 years ago

It works now, thank you!