8000 Merge branch 'release/1.7.0.5' · rdotnet/rdotnet@de462e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit de462e2

Browse files
committed
Merge branch 'release/1.7.0.5'
2 parents bff6613 + c97910a commit de462e2

11 files changed

+102
-26
lines changed

R.NET/CharacterMatrix.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ protected internal CharacterMatrix(REngine engine, IntPtr coerced)
6363
{
6464
int offset = GetOffset(rowIndex, columnIndex);
6565
IntPtr pointer = Marshal.ReadIntPtr(DataPointer, offset);
66+
if (pointer == Engine.NaStringPointer)
67+
{
68+
return null;
69+
}
6670
return new InternalString(Engine, pointer);
6771
}
6872
}
@@ -83,14 +87,20 @@ protected internal CharacterMatrix(REngine engine, IntPtr coerced)
8387
}
8488
}
8589

90+
private Rf_mkChar _mkChar = null;
91+
92+
private IntPtr mkChar(string value)
93+
{
94+
if (_mkChar == null)
95+
_mkChar = this.GetFunction<Rf_mkChar>();
96+
return _mkChar(value);
97+
}
98+
8699
private void SetValue(int rowIndex, int columnIndex, string value)
87100
{
88101
int offset = GetOffset(rowIndex, columnIndex);
89-
SymbolicExpression s = value == null ? Engine.NilValue : new InternalString(Engine, value);
90-
using (new ProtectedPointer(s))
91-
{
92-
Marshal.WriteIntPtr(DataPointer, offset, s.DangerousGetHandle());
93-
}
102+
IntPtr stringPointer = value == null ? Engine.NaStringPointer : mkChar(value);
103+
Marshal.WriteIntPtr(DataPointer, offset, stringPointer);
94104
}
95105

96106
/// <summary>

R.NET/ExpressionVector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected override void SetVectorDirect(Expression[] values)
9393
{
9494
SetValueAltRep(i, values[i]);
9595
}
96+
else
9697
{
9798
SetValue(i, values[i]);
9899
}

R.NET/GenericVector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ protected override void SetVectorDirect(SymbolicExpression[] values)
115115
{
116116
SetValueAltRep(i, values[i]);
117117
}
118+
else
118119
{
119120
SetValue(i, values[i]);
120121
}

R.NET/Properties/VersionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated/>
22
using System.Reflection;
33

4-
[assembly: AssemblyVersionAttribute("1.7.0.4")]
5-
[assembly: AssemblyFileVersionAttribute("1.7.0.4")]
4+
[assembly: AssemblyVersionAttribute("1.7.0.5")]
5+
[assembly: AssemblyFileVersionAttribute("1.7.0.5")]

R.NET/RDotNet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<AppDesignerFolder>Properties</AppDesignerFolder>
99
<RootNamespace>RDotNet</RootNamespace>
1010
<AssemblyName>RDotNet</AssemblyName>
11-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1414
<RestorePackages>true</RestorePackages>

RDotNet.Graphics/RDotNet.Graphics.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -8,7 +8,7 @@
88
<AppDesignerFolder>Properties</AppDesignerFolder>
99
<RootNamespace>RDotNet.Graphics</RootNamespace>
1010
<AssemblyName>RDotNet.Graphics</AssemblyName>
11-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1414
<RestorePackages>true</RestorePackages>

RDotNet.NativeLibrary/RDotNet.NativeLibrary.csproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<AppDesignerFolder>Properties</AppDesignerFolder>
99
<RootNamespace>RDotNet.NativeLibrary</RootNamespace>
1010
<AssemblyName>RDotNet.NativeLibrary</AssemblyName>
11-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1414
<RestorePackages>true</RestorePackages>
@@ -76,6 +76,10 @@
7676
<Project>{37e8df32-0d37-418e-b976-10f4b36a0073}</Project>
7777
<Name>DynamicInterop</Name>
7878
</ProjectReference>
79+
<ProjectReference Include="..\..\dynamic-interop-dll\DynamicInterop\DynamicInterop.csproj">
80+
<Project>{37e8df32-0d37-418e-b976-10f4b36a0073}</Project>
81+
<Name>DynamicInterop</Name>
82+
</ProjectReference>
7983
</ItemGroup>
8084
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8185
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -86,14 +90,6 @@
8690
</Target>
8791
-->
8892
<Choose>
89-
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.7.1' Or $(TargetFrameworkVersion) == 'v4.7.2')) Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v2.1')) Or ($(TargetFrameworkIdentifier) == '.NETStandard' And $(TargetFrameworkVersion) == 'v2.0') Or ($(TargetFrameworkIdentifier) == '.NETCore' And $(TargetFrameworkVersion) == 'v5.0')">
90-
<ItemGroup>
91-
<Reference Include="DynamicInterop">
92-
<HintPath>..\packages\DynamicInterop\lib\netstandard2.0\DynamicInterop.dll</HintPath>
93-
<Private>True</Private>
94-
<Paket>True</Paket>
95-
</Reference>
96-
</ItemGroup>
97-
</When>
93+
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.7.1' Or $(TargetFrameworkVersion) == 'v4.7.2')) Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v2.1')) Or ($(TargetFrameworkIdentifier) == '.NETStandard' And $(TargetFrameworkVersion) == 'v2.0') Or ($(TargetFrameworkIdentifier) == '.NETCore' And $(TargetFrameworkVersion) == 'v5.0')" />
9894
</Choose>
9995
</Project>

RDotNet.TestBase/RDotNet.TestBase.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
55
<PropertyGroup>
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>RDotNet</RootNamespace>
1212
<AssemblyName>RDotNet.TestBase</AssemblyName>
13-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1616
<RestorePackages>true</RestorePackages>

RDotNet.Tests/CharacterMatrixTest.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Xunit;
2+
3+
namespace RDotNet
4+
{
5+
public class CharacterMatrixTest : RDotNetTestFixture
6+
{
7+
[Fact]
8+
public void TestCharacter()
9+
{
10+
SetUpTest();
11+
var engine = this.Engine;
12+
var matrix = engine.Evaluate("x <- matrix(c(1, NA, 2, 3, NA, 4), nrow=3, ncol=2, byrow=TRUE)").AsCharacterMatrix();
13+
Assert.Equal(3, matrix.RowCount);
14+
Assert.Equal(2, matrix.ColumnCount);
15+
Assert.Equal("1", matrix[0,0]);
16+
Assert.Null(matrix[0,1]);
17+
Assert.Equal("2", matrix[1, 0]);
18+
Assert.Equal("3", matrix[1, 1]);
19+
Assert.Null(matrix[2, 0]);
20+
Assert.Equal("4", matrix[2, 1]);
21+
22+
matrix[0, 0] = null;
23+
matrix[0, 1] = "A";
24+
Assert.Null(matrix[0,0]);
25+
Assert.Equal("A", matrix[0, 1]);
26+
27+
var logical = engine.Evaluate("is.na(x)").AsLogical(); // This gets strung out as col1 + col2
28+
// The original x was never modified, just our copy of it did. So the logical should reflect the
29+
// original value of x.
30+
Assert.False(logical[0]); // 1
31+
Assert.False(logical[1]); // 2
32+
Assert.True(logical[2]); // NA
33+
Assert.True(logical[3]); // NA
34+
Assert.False(logical[4]); // 3
35+
Assert.False(logical[5]); // 4
36+
}
37+
38+
[Fact]
39+
public void TestCharacter_NoConversion()
40+
{
41+
SetUpTest();
42+
var engine = this.Engine;
43+
var matrix = engine.Evaluate("x <- matrix(c('1', NA, '2', '3', NA, '4'), nrow=3, ncol=2, byrow=TRUE)").AsCharacterMatrix();
44+
Assert.Equal(3, matrix.RowCount);
45+
Assert.Equal(2, matrix.ColumnCount);
46+
Assert.Equal("1", matrix[0, 0]);
47+
Assert.Null(matrix[0, 1]);
48+
Assert.Equal("2", matrix[1, 0]);
49+
Assert.Equal("3", matrix[1, 1]);
50+
Assert.Null(matrix[2, 0]);
51+
Assert.Equal("4", matrix[2, 1]);
52+
53+
matrix[0, 0] = null;
54+
matrix[0, 1] = "A";
55+
Assert.Null(matrix[0, 0]);
56+
Assert.Equal("A", matrix[0, 1]);
57+
58+
var logical = engine.Evaluate("is.na(x)").AsLogical();
59+
Assert.True(logical[0]); // Was 1, now NA because we modified the original x
60+
Assert.False(logical[1]); // 2
61+
Assert.True(logical[2]); // NA
62+
Assert.False(logical[3]); // "A"
63+
Assert.False(logical[4]); // 3
64+
Assert.False(logical[5]); // 4
65+
}
66+
}
67+
}

RDotNet.Tests/RDotNet.Tests.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props" Condition="Exists('..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props')" />
44
<Import Project="..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
55
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
@@ -11,7 +11,7 @@
1111
<AppDesignerFolder>Properties</AppDesignerFolder>
1212
<RootNamespace>RDotNet</RootNamespace>
1313
<AssemblyName>RDotNet.Tests</AssemblyName>
14-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1515
<FileAlignment>512</FileAlignment>
1616
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1717
<RestorePackages>true</RestorePackages>
@@ -76,10 +76,11 @@
7676
</Reference>
7777
</ItemGroup>
7878
<ItemGroup>
79+
<Compile Include="CharacterMatrixTest.cs" />
80+
<Compile Include="CharacterVectorTest.cs" />
7981
<Compile Include="MultiThreadingTest.cs" />
8082
<Compile Include="S4ClassesTest.cs" />
8183
<Compile Include="ListsTest.cs" />
82-
<Compile Include="CharacterVectorTest.cs" />
8384
<Compile Include="REngineInitTest.cs" />
8485
<Compile Include="DataConversionTest.cs" />
8586
<Compile Include="EnvironmentTest.cs" />

RDotNet.Tests/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<package id="xunit.core" version="2.0.0" targetFramework="net45" />
88
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net45" />
99
<package id="xunit.MSBuild" version="2.0.0.0" targetFramework="net45" developmentDependency="true" />
10-
<package id="xunit.runner.console" version="2.4.1" targetFramework="net45" developmentDependency="true" />
10+
<package id="xunit.runner.console" version="2.4.1" targetFramework="net45" developmentDependency="true" requireReinstallation="True" />
1111
<package id="xunit.runner.visualstudio" version="2.4.1" targetFramework="net45" developmentDependency="true" />
1212
</packages>

0 commit comments

Comments
 (0)
0