Skip to content

Instantly share code, notes, and snippets.

@luajalla
Created October 10, 2013 19:52
Show Gist options
  • Save luajalla/6924468 to your computer and use it in GitHub Desktop.
Save luajalla/6924468 to your computer and use it in GitHub Desktop.
REngine initialization (Mono + OSX, R 2.15 32bit) - Console app works - Type provider crashes (added a script file with #r to it)
namespace rtest
open System
open RDotNet
[<AutoOpen>]
module Init =
let initR() =
let rpath = "/Library/Frameworks/R.framework/Libraries"
let rresources = "/Library/Frameworks/R.framework/Resources"
let oldpath = Environment.GetEnvironmentVariable "PATH"
Environment.SetEnvironmentVariable("PATH", sprintf "%s:%s" rpath oldpath)
Environment.SetEnvironmentVariable("R_HOME", rresources)
let engine = REngine.CreateInstance("RDotNet")
engine.Initialize()
let e = engine.Evaluate("1 + 3");
e.AsNumeric()
[<EntryPoint>]
let main args =
initR() |> printfn "%A" //seq [4.0]
0
// type provider library
namespace rtest
open Microsoft.FSharp.Core.CompilerServices
open Samples.FSharp.ProvidedTypes
[<TypeProvider>]
type RProvider(cfg: TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()
let asm = System.Reflection.Assembly.GetExecutingAssembly()
let ns = "REngineRepro"
let ty = ProvidedTypeDefinition(asm, ns, "R", Some typeof<obj>)
do
initR() |> ignore
this.AddNamespace(ns, [ty])
[<TypeProviderAssembly>]
do ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment