Skip to content

Commit

Permalink
work for documentation of next R.NET release (1.6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmp75 committed Feb 27, 2014
1 parent 0e4576d commit 65746f4
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 107 deletions.
18 changes: 8 additions & 10 deletions HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RDotNet">
<HintPath>..\Binaries\RDotNet.dll</HintPath>
<Reference Include="RDotNet, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.dll</HintPath>
</Reference>
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\Binaries\RDotNet.NativeLibrary.dll</HintPath>
<Reference Include="RDotNet.NativeLibrary, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -54,12 +57,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RDotNetSetup\RDotNetSetup.csproj">
<Project>{5A41CEBA-0BB9-4802-915E-86B951A41AF0}</Project>
<Name>RDotNetSetup</Name>
</ProjectReference>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
36 changes: 17 additions & 19 deletions HelloWorld/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using RDotNet;
using RDotNet.NativeLibrary;
using RDotNetSetup;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -10,22 +9,21 @@

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
REngine.SetEnvironmentVariables(); // Currently under development - coming soon
using (REngine engine = REngine.CreateInstance("RDotNet"))
{
engine.Initialize(); // required since v1.5
CharacterVector charVec = engine.CreateCharacterVector(new[] { "Hello, R world!, .NET speaking" });
engine.SetSymbol("greetings", charVec);
engine.Evaluate("str(greetings)"); // print out in the console
string[] a = engine.Evaluate("'Hi there .NET, from the R engine'").AsCharacter().ToArray();
Console.WriteLine("R answered: '{0}'", a[0]);
Console.WriteLine("Press any key to exit the program");
Console.ReadKey();
}
}
}
class Program
{
static void Main(string[] args)
{
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();
engine.Initialize(); // required since v1.5
CharacterVector charVec = engine.CreateCharacterVector(new[] { "Hello, R world!, .NET speaking" });
engine.SetSymbol("greetings", charVec);
engine.Evaluate("str(greetings)"); // print out in the console
string[] a = engine.Evaluate("'Hi there .NET, from the R engine'").AsCharacter().ToArray();
Console.WriteLine("R answered: '{0}'", a[0]);
Console.WriteLine("Press any key to exit the program");
Console.ReadKey();
engine.Dispose();
}
}
}
4 changes: 4 additions & 0 deletions HelloWorld/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="R.NET" version="1.5.6" targetFramework="net45" />
</packages>
8 changes: 1 addition & 7 deletions OnboardRDotNet.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "HelloWorld\HelloWorld.csproj", "{08244E5B-EF06-41FC-B81A-D8E0415292F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RDotNetSetup", "RDotNetSetup\RDotNetSetup.csproj", "{5A41CEBA-0BB9-4802-915E-86B951A41AF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tutorial1", "Tutorial1\Tutorial1.csproj", "{2E34B44E-B7E5-411A-B4E7-D4E2FB270CFF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample1", "Sample1\Sample1.csproj", "{76547291-72A6-432F-9CD0-C07CB3E6BE35}"
Expand All @@ -32,10 +30,6 @@ Global
{08244E5B-EF06-41FC-B81A-D8E0415292F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08244E5B-EF06-41FC-B81A-D8E0415292F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08244E5B-EF06-41FC-B81A-D8E0415292F4}.Release|Any CPU.Build.0 = Release|Any CPU
{5A41CEBA-0BB9-4802-915E-86B951A41AF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A41CEBA-0BB9-4802-915E-86B951A41AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A41CEBA-0BB9-4802-915E-86B951A41AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A41CEBA-0BB9-4802-915E-86B951A41AF0}.Release|Any CPU.Build.0 = Release|Any CPU
{2E34B44E-B7E5-411A-B4E7-D4E2FB270CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E34B44E-B7E5-411A-B4E7-D4E2FB270CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E34B44E-B7E5-411A-B4E7-D4E2FB270CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
22 changes: 11 additions & 11 deletions Optimization/Optimization.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -27,24 +27,24 @@
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="RDotNet">
<HintPath>..\Binaries\RDotNet.dll</HintPath>
<Reference Include="RDotNet, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.dll</HintPath>
</Reference>
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\Binaries\RDotNet.NativeLibrary.dll</HintPath>
<Reference Include="RDotNet.NativeLibrary, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\RDotNetSetup\RDotNetSetup.csproj">
<Project>{5A41CEBA-0BB9-4802-915E-86B951A41AF0}</Project>
<Name>RDotNetSetup</Name>
</ProjectReference>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 0 additions & 1 deletion Optimization/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using RDotNet;
using RDotNetSetup;
using System.Linq;

namespace Optimization
Expand Down
4 changes: 4 additions & 0 deletions Optimization/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="R.NET" version="1.5.6" targetFramework="net40" />
</packages>
3 changes: 0 additions & 3 deletions RDotNetSetup/RDotNetSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\Binaries\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SetupHelper.cs" />
Expand Down
59 changes: 29 additions & 30 deletions Sample1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
using RDotNet;
using RDotNetSetup;
using System;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RDotNet;

namespace Sample1
{
class Program
{
static void Main(string[] args)
{
SetupHelper.SetupPath();
using (REngine engine = REngine.CreateInstance("RDotNet"))
{
// From v1.5, REngine requires explicit initialization.
// You can set some parameters.
engine.Initialize();
class Program
{
static void Main(string[] args)
{
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();
// REngine requires explicit initialization.
// You can set some parameters.
engine.Initialize();

// .NET Framework array to R vector.
NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
engine.SetSymbol("group1", group1);
// Direct parsing from R script.
NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();
// .NET Framework array to R vector.
NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });
engine.SetSymbol("group1", group1);
// Direct parsing from R script.
NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();

// Test difference of mean and get the P-value.
GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList();
double p = testResult["p.value"].AsNumeric().First();
// Test difference of mean and get the P-value.
GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList();
double p = testResult["p.value"].AsNumeric().First();

Console.WriteLine("Group1: [{0}]", string.Join(", ", group1));
Console.WriteLine("Group2: [{0}]", string.Join(", ", group2));
Console.WriteLine("P-value = {0:0.000}", p);
}
}
}
Console.WriteLine("Group1: [{0}]", string.Join(", ", group1));
Console.WriteLine("Group2: [{0}]", string.Join(", ", group2));
Console.WriteLine("P-value = {0:0.000}", p);

// you should always dispose of the REngine properly.
// After disposing of the engine, you cannot reinitialize nor reuse it
engine.Dispose();

}
}
}
18 changes: 8 additions & 10 deletions Sample1/Sample1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RDotNet">
<HintPath>..\Binaries\RDotNet.dll</HintPath>
<Reference Include="RDotNet, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.dll</HintPath>
</Reference>
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\Binaries\RDotNet.NativeLibrary.dll</HintPath>
<Reference Include="RDotNet.NativeLibrary, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -54,12 +57,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RDotNetSetup\RDotNetSetup.csproj">
<Project>{5A41CEBA-0BB9-4802-915E-86B951A41AF0}</Project>
<Name>RDotNetSetup</Name>
</ProjectReference>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
4 changes: 4 additions & 0 deletions Sample1/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="R.NET" version="1.5.6" targetFramework="net45" />
</packages>
18 changes: 8 additions & 10 deletions Sample2/Sample2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RDotNet">
<HintPath>..\Binaries\RDotNet.dll</HintPath>
<Reference Include="RDotNet, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.dll</HintPath>
</Reference>
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\Binaries\RDotNet.NativeLibrary.dll</HintPath>
<Reference Include="RDotNet.NativeLibrary, Version=1.5.6.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -54,12 +57,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RDotNetSetup\RDotNetSetup.csproj">
<Project>{5A41CEBA-0BB9-4802-915E-86B951A41AF0}</Project>
<Name>RDotNetSetup</Name>
</ProjectReference>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
4 changes: 4 additions & 0 deletions Sample2/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="R.NET" version="1.5.6" targetFramework="net45" />
</packages>
8 changes: 8 additions & 0 deletions Tutorial1/Tutorial1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RDotNet">
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.dll</HintPath>
</Reference>
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\packages\R.NET.1.5.6\lib\net40\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -48,6 +55,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
4 changes: 4 additions & 0 deletions Tutorial1/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="R.NET" version="1.5.6" targetFramework="net45" />
</packages>
6 changes: 0 additions & 6 deletions WebApplicationRdn/WebApplicationRdn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="RDotNet">
<HintPath>..\Binaries\RDotNet.dll</HintPath>
</Reference>
<Reference Include="RDotNet.NativeLibrary">
<HintPath>..\Binaries\RDotNet.NativeLibrary.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
Expand Down

0 comments on commit 65746f4

Please sign in to comment.