Skip to content

Commit 06223a9

Browse files
committed
read/write of the r# dataframe in binary file format
1 parent 60ffb45 commit 06223a9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

R#/Runtime/Internal/internalInvokes/file.vb

+23
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ Namespace Runtime.Internal.Invokes
122122
<Package("file")>
123123
Public Module file
124124

125+
Sub New()
126+
Call generic.add("writeBin", GetType(dataframe), AddressOf writeBinDataframe)
127+
Call generic.add("readBin.dataframe", GetType(Stream), AddressOf readBinDataframe)
128+
End Sub
129+
125130
''' <summary>
126131
''' # Generate SHA1 checksum of a file
127132
''' </summary>
@@ -1512,6 +1517,24 @@ Namespace Runtime.Internal.Invokes
15121517
Return out
15131518
End Function
15141519

1520+
<RGenericOverloads("writeBin")>
1521+
Private Function writeBinDataframe(dataframe As dataframe, args As list, env As Environment) As Object
1522+
Dim con As Stream = args!con
1523+
Dim buffer As New dataframeBuffer(dataframe, env)
1524+
1525+
Call buffer.Serialize(con)
1526+
Call con.Flush()
1527+
1528+
Return True
1529+
End Function
1530+
1531+
<RGenericOverloads("readBin.dataframe")>
1532+
Private Function readBinDataframe(s As Stream, args As list, env As Environment) As Object
1533+
Dim buffer As New dataframeBuffer(s)
1534+
Dim df As dataframe = buffer.getFrame
1535+
Return df
1536+
End Function
1537+
15151538
''' <summary>
15161539
''' close connections, i.e., “generalized files”, such as possibly compressed files, URLs, pipes, etc.
15171540
''' </summary>

R#/Runtime/Serialize/bufferObjects/dataframeBuffer.vb

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Namespace Runtime.Serialize
9393
Call MyBase.New(data)
9494
End Sub
9595

96+
''' <summary>
97+
''' write dataframe value to binary file
98+
''' </summary>
99+
''' <param name="buffer"></param>
96100
Public Overrides Sub Serialize(buffer As Stream)
97101
Dim colnames As String() = dataframe.colnames
98102
Dim rownames As String() = dataframe.getRowNames

0 commit comments

Comments
 (0)