Using the R type provider with MBrace
In this tutorial, you will learn how you can use MBrace to distribute code that utilises the R Type Provider.
Installing R across your cluster
First of all, we define a bit of MBrace code that performs installation of R components on an MBrace cluster. This assumes that worker processes are run with elevated permisions. As of MBrace.Azure v 1.1.5, bundled cloud service packages have elevated permissions enabled. If your cluster does not come with elevated permissions, please ensure that R is already installed across your workers.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: |
|
We can now install R across the cluster by calling
1:
|
|
And verify that the operation was successful
1:
|
|
Deploying R provider code to your cluster
We are now ready to begin using the R type provider with MBrace. Here is a simple, non-parallel example taken from the R Type Provider tutorial.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: |
|
In this tutorial, you've learned how to use the R type provider using MBrace.
Continue with further samples to learn more about the MBrace programming model.
Note, you can use the above techniques from both scripts and compiled projects. To see the components referenced by this script, see ThespianCluster.fsx or AzureCluster.fsx.
Full name: 200-using-r-provider.cluster
Full name: Config.GetCluster
Gets or creates a new Thespian cluster session.
Full name: 200-using-r-provider.R_Installer
Path to R installer mirror; change as appropriate
Full name: 200-using-r-provider.isRInstalled
checks whether R is installed in the local computer
static val CurrentUser : RegistryKey
static val LocalMachine : RegistryKey
static val ClassesRoot : RegistryKey
static val Users : RegistryKey
static val PerformanceData : RegistryKey
static val CurrentConfig : RegistryKey
static val DynData : RegistryKey
static member GetValue : keyName:string * valueName:string * defaultValue:obj -> obj
static member SetValue : keyName:string * valueName:string * value:obj -> unit + 1 overload
Full name: Microsoft.Win32.Registry
Win32.RegistryKey.OpenSubKey(name: string, permissionCheck: Win32.RegistryKeyPermissionCheck) : Win32.RegistryKey
Win32.RegistryKey.OpenSubKey(name: string, writable: bool) : Win32.RegistryKey
Win32.RegistryKey.OpenSubKey(name: string, permissionCheck: Win32.RegistryKeyPermissionCheck, rights: Security.AccessControl.RegistryRights) : Win32.RegistryKey
Full name: 200-using-r-provider.installR
Performs R installation operation on an MBrace cluster
Assumes workers running with elevated privileges
Full name: Microsoft.FSharp.Core.Operators.not
from MBrace.Library
type WebClient =
inherit Component
new : unit -> WebClient
member BaseAddress : string with get, set
member CachePolicy : RequestCachePolicy with get, set
member CancelAsync : unit -> unit
member Credentials : ICredentials with get, set
member DownloadData : address:string -> byte[] + 1 overload
member DownloadDataAsync : address:Uri -> unit + 1 overload
member DownloadFile : address:string * fileName:string -> unit + 1 overload
member DownloadFileAsync : address:Uri * fileName:string -> unit + 1 overload
member DownloadString : address:string -> string + 1 overload
...
Full name: System.Net.WebClient
--------------------
WebClient() : unit
static val DirectorySeparatorChar : char
static val AltDirectorySeparatorChar : char
static val VolumeSeparatorChar : char
static val InvalidPathChars : char[]
static val PathSeparator : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
Path.Combine(path1: string, path2: string) : string
Path.Combine(path1: string, path2: string, path3: string) : string
Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
type Uri =
new : uriString:string -> Uri + 5 overloads
member AbsolutePath : string
member AbsoluteUri : string
member Authority : string
member DnsSafeHost : string
member Equals : comparand:obj -> bool
member Fragment : string
member GetComponents : components:UriComponents * format:UriFormat -> string
member GetHashCode : unit -> int
member GetLeftPart : part:UriPartial -> string
...
Full name: System.Uri
--------------------
Uri(uriString: string) : unit
Uri(uriString: string, uriKind: UriKind) : unit
Uri(baseUri: Uri, relativeUri: string) : unit
Uri(baseUri: Uri, relativeUri: Uri) : unit
type ProcessStartInfo =
new : unit -> ProcessStartInfo + 2 overloads
member Arguments : string with get, set
member CreateNoWindow : bool with get, set
member Domain : string with get, set
member EnvironmentVariables : StringDictionary
member ErrorDialog : bool with get, set
member ErrorDialogParentHandle : nativeint with get, set
member FileName : string with get, set
member LoadUserProfile : bool with get, set
member Password : SecureString with get, set
...
Full name: System.Diagnostics.ProcessStartInfo
--------------------
ProcessStartInfo() : unit
ProcessStartInfo(fileName: string) : unit
ProcessStartInfo(fileName: string, arguments: string) : unit
type Process =
inherit Component
new : unit -> Process
member BasePriority : int
member BeginErrorReadLine : unit -> unit
member BeginOutputReadLine : unit -> unit
member CancelErrorRead : unit -> unit
member CancelOutputRead : unit -> unit
member Close : unit -> unit
member CloseMainWindow : unit -> bool
member EnableRaisingEvents : bool with get, set
member ExitCode : int
...
Full name: System.Diagnostics.Process
--------------------
Process() : unit
Process.Start(fileName: string) : Process
Process.Start(fileName: string, arguments: string) : Process
Process.Start(fileName: string, userName: string, password: Security.SecureString, domain: string) : Process
Process.Start(fileName: string, arguments: string, userName: string, password: Security.SecureString, domain: string) : Process
Full name: Microsoft.FSharp.Core.Operators.invalidOp
Full name: 200-using-r-provider.isRInstalledCloud
Parallel workflow that verifies whether R is successfully installed across the cluster
member Clone : unit -> obj
member CopyTo : array:Array * index:int -> unit + 1 overload
member GetEnumerator : unit -> IEnumerator
member GetLength : dimension:int -> int
member GetLongLength : dimension:int -> int64
member GetLowerBound : dimension:int -> int
member GetUpperBound : dimension:int -> int
member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
member Initialize : unit -> unit
member IsFixedSize : bool
...
Full name: System.Array
Full name: Microsoft.FSharp.Collections.Array.forall
Full name: Microsoft.FSharp.Core.Operators.id
Full name: 200-using-r-provider.testR
type Random =
new : unit -> Random + 1 overload
member Next : unit -> int + 2 overloads
member NextBytes : buffer:byte[] -> unit
member NextDouble : unit -> float
Full name: System.Random
--------------------
Random() : unit
Random(Seed: int) : unit
Full name: RProvider.Helpers.namedParams
Full name: Microsoft.FSharp.Core.Operators.box
static member ``<Error>`` : string
Full name: RProvider.R