fslaborg / RProvider

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

Strange difference between fsx script and fs program #164

Closed mae1st0rm closed 8 years ago

mae1st0rm commented 8 years ago

Hello! i faced strange situation: if i put code in fsx script it runs ok, but if i put code inside Console application it fails for some reason:

open System
open RDotNet
open RProvider
open RProvider.graphics

let eval (text:string) =
  R.eval(R.parse(namedParams ["text", text])) 
let code = 
    @"
    x <- 3.1415
    sin(x)
    "
let f () = code |> eval
let engine = REngine.GetInstance()
// this works fine
let y0 = engine.Evaluate(code).GetValue<float>()
// this fails in Console app, but works in script - why?
let y1 = f().GetValue<float>()
Console.ReadLine() |> ignore

Some details: R version 3.2.0, Win7x64, VS2015, RProvider 1.1.15

tpetricek commented 8 years ago

What is the error message that you are getting?

tpetricek commented 8 years ago

Also, if you cold produce & share a log file with more details, that would be great. You can follow the instructions from: http://bluemountaincapital.github.io/FSharpRProvider/diagnostics.html

mae1st0rm commented 8 years ago

Exception message:

Error in base::parse(text = fsr_10064_1) : :1:1: unexpected input 1: ^

Part of stacktrace:

in RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement) in RDotNet.REngine.d__0.MoveNext() in System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source) in RDotNet.REngine.Evaluate(String statement) in RProvider.RInteropInternal.eval@292.Invoke(Unit unitVar0) in c:\Tomas\Public\bmc\FSharp.RProvider\src\RProvider\RInterop.fs:line 294 ....

Seems that R can't parse input string with linebreaks for some reason, not sure though

mae1st0rm commented 8 years ago

rlog.txt Log file

tpetricek commented 8 years ago

Looks like R engine does not like \r characters:

// Works
R.eval(R.parse(text="x<-3.14\nsin(x)"))
// Does not work
R.eval(R.parse(text="x<-3.14\r\nsin(x)"))