Skip to content

Commit

Permalink
Refactored issue #29; addressed issue #1 with R_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
geandbe committed Aug 12, 2013
1 parent 236e169 commit 9766d24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
22 changes: 22 additions & 0 deletions RInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ module Helpers =
let (|Null|_|) (sexp: SymbolicExpression) = if sexp <> null && sexp.Type = SymbolicExpressionType.Null then Some() else None
let (|Symbol|_|) (sexp: SymbolicExpression) = if sexp <> null && sexp.Type = SymbolicExpressionType.Symbol then Some(sexp.AsSymbol()) else None

open Microsoft.Win32
open System.IO
let selectRLocation is64bit =
let locateRfromRegistry is64bit =
let rCore =
match Registry.LocalMachine.OpenSubKey @"SOFTWARE\R-core", Registry.CurrentUser.OpenSubKey @"SOFTWARE\R-core" with
| null, null -> failwithf "Reg key Software\R-core does not exist; R is likely not installed on this computer"
| null, x -> x
| x, null -> x
| _ as x, _ -> x

let subKeyName = if is64bit then "R64" else "R"
let key = rCore.OpenSubKey subKeyName
if key = null then
failwithf "SOFTWARE\R-core exists but subkey %s does not exist" subKeyName

key.GetValue "InstallPath" |> unbox

match Environment.GetEnvironmentVariable "R_HOME" with
| null -> locateRfromRegistry is64bit
| rPath -> rPath

module internal RInteropInternal =
type RParameter = string
type HasVarArgs = bool
Expand Down
19 changes: 3 additions & 16 deletions RProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,17 @@ open Microsoft.FSharp.Core.CompilerServices
open RDotNet
open RInteropInternal
open RInterop
open Microsoft.Win32

[<TypeProvider>]
type public RProvider(cfg:TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()

// R potentially may be not installed - handle this in static constructor for improved diag (G.B.)
static do
// If the registry is set up, use that for configuring the path
let rCore =
match Registry.LocalMachine.OpenSubKey(@"SOFTWARE\R-core"), Registry.CurrentUser.OpenSubKey(@"SOFTWARE\R-core") with
| null, null -> failwithf "Reg key Software\R-core does not exist; R is likely not installed on this computer"
| null, x -> x
| x, null -> x
| _ as x, _ -> x

let is64bit = Environment.Is64BitProcess
let subKeyName = if is64bit then "R64" else "R"
let key = rCore.OpenSubKey(subKeyName)
if key = null then
failwithf "SOFTWARE\R-core exists but subkey %s does not exist" subKeyName

let installPath = key.GetValue("InstallPath") :?> string
let binPath = Path.Combine(installPath, "bin", if is64bit then "x64" else "i386")
let binPath = Path.Combine(selectRLocation is64bit, "bin", if is64bit then "x64" else "i386")
if not (Path.Combine(binPath, "R.dll") |> File.Exists) then
failwithf "No R engine at %s" binPath

// Set the path
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + binPath)
Expand Down

0 comments on commit 9766d24

Please sign in to comment.