Skip to content

Commit

Permalink
Merge pull request #21 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating branch
  • Loading branch information
mmulahvictor authored May 17, 2022
2 parents 227178f + 2309005 commit 9965249
Show file tree
Hide file tree
Showing 214 changed files with 10,824 additions and 6,991 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,7 @@ ModelManifest.xml
/instat/static/InstatObject/R/examples.R
/instat/static/Library/
installer/Output/
/instat/dlgFrequency.vb
/instat/dlgFrequency.sw-KE.resx
/instat/dlgFrequency.resx
/instat/dlgFrequency.Designer.vb
6 changes: 3 additions & 3 deletions docs/Download.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2 class="section-heading">Download R-Instat</h2>
<p><strong>In response to the recent <a href=https://r4stats.com/articles/software-reviews/r-instat/ style="color:blue;" target="_blank">review of R-Instat</a> by Bob Muenchen we have released a new version of R-Instat, version 0.7.4, which includes some new features and initial improvements from the review. Many thanks to Bob for reviewing R-Instat.</strong></p>
<p><strong>In response to the recent <a href=https://r4stats.com/articles/software-reviews/r-instat/ style="color:blue;" target="_blank">review of R-Instat</a> by Bob Muenchen we have released a new version of R-Instat, version 0.7.5, which includes some new features and initial improvements from the review. Many thanks to Bob for reviewing R-Instat.</strong></p>
<hr class="light">
<p><a href=https://downloads.r-instat.org/R-Instat_0.7.4_Installer_32.exe style="color:blue;" target="_blank">R-Instat 0.7.4 Installer 32 Bit (.exe 734MB)</a></p>
<p><a href=https://downloads.r-instat.org/R-Instat_0.7.5_Installer_32.exe style="color:blue;" target="_blank">R-Instat 0.7.5 Installer 32 Bit (.exe 734MB)</a></p>
<p>If you know that you have a 64 bit computer, we suggest you download the 64 Bit version</p>
<a href=https://downloads.r-instat.org/R-Instat_0.7.4_Installer_64.exe style="color:blue;" target="_blank">R-Instat 0.7.4 Installer 64 Bit (.exe 736MB)</a>
<a href=https://downloads.r-instat.org/R-Instat_0.7.5_Installer_64.exe style="color:blue;" target="_blank">R-Instat 0.7.5 Installer 64 Bit (.exe 736MB)</a>
<p>R-Instat is currently a Windows only application. However, it can be accessed on Mac or Linux through use of a Virtual Windows Machine.</p>

<h2 class="section-heading">Installation & Documentation</h2>
Expand Down
2 changes: 2 additions & 0 deletions instat/Interface/IColumnMetaDataGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Public Interface IColumnMetaDataGrid

Event EditValue(iRow As Integer, strColumnName As String, strPreviousValue As String, newValue As Object)

Event DeleteLabels(strColumnName As String)

Sub AddColumns(columnMetaData As clsColumnMetaData)

Sub AddRowData(columnMetaData As clsColumnMetaData)
Expand Down
2 changes: 2 additions & 0 deletions instat/Interface/IDataframeMetaDataGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Public Interface IDataframeMetaDataGrid

Event EditValue(iRow As Integer, strColumnName As String, strPreviousValue As String, newValue As Object)

Event DeleteLabels(strColumnName As String)

Sub AddColumns()

Sub AddRowData()
Expand Down
53 changes: 33 additions & 20 deletions instat/Model/DataFrame/clsColumnMetaData.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports RDotNet

''' <summary>
''' Holds Column Meta Data for a single dataframe
''' </summary>
Public Class clsColumnMetaData
Private _strName As String
Private _strDataFrameName As String
Private _RLink As RLink
Private _clsDataFrame As DataFrame
Private Property _clsColsMetadataDataFrame As DataFrame
Private _hasChanged As Boolean

''' <summary>
''' holds the metadata change audit id
''' </summary>
Public Property MetadataChangeAuditId As Integer

''' <summary>
''' Returns data for a given cell within the Column Meta data table
''' </summary>
''' <param name="row"></param>
''' <param name="column"></param>
''' <param name="iRowIndex"></param>
''' <param name="iColumnIndex"></param>
''' <returns></returns>
Public ReadOnly Property Data(row As Integer, column As Integer) As Object
Public ReadOnly Property Data(iRowIndex As Integer, iColumnIndex As Integer) As Object
Get
Return _clsDataFrame(row, column)
Return _clsColsMetadataDataFrame.Item(iRowIndex, iColumnIndex)
End Get
End Property

Expand All @@ -43,7 +49,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property strRowName(row As Integer) As String
Get
Return _clsDataFrame.RowNames(row)
Return _clsColsMetadataDataFrame.RowNames(row)
End Get
End Property

Expand All @@ -53,7 +59,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property iRowCount As Integer
Get
Return _clsDataFrame.RowCount
Return _clsColsMetadataDataFrame.RowCount
End Get
End Property

Expand All @@ -64,7 +70,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property strColumnName(column As Integer) As String
Get
Return _clsDataFrame.ColumnNames(column)
Return _clsColsMetadataDataFrame.ColumnNames(column)
End Get
End Property

Expand All @@ -74,7 +80,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property iColumnCount As Integer
Get
Return _clsDataFrame.ColumnCount
Return _clsColsMetadataDataFrame.ColumnCount
End Get
End Property

Expand All @@ -87,7 +93,7 @@ Public Class clsColumnMetaData
Get
Return _hasChanged
End Get
Set(ByVal value As Boolean)
Set(value As Boolean)
_hasChanged = value
End Set
End Property
Expand All @@ -99,15 +105,15 @@ Public Class clsColumnMetaData
''' <param name="strName"></param>
Public Sub New(rLink As RLink, strName As String)
_RLink = rLink
_strName = strName
_strDataFrameName = strName
_hasChanged = True
End Sub

Private Function HasDataChanged() As Boolean
Dim clsVariablesMetadataChanged As New RFunction
Dim expTemp As SymbolicExpression
clsVariablesMetadataChanged.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata_changed")
clsVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strName & Chr(34))
clsVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34))
expTemp = _RLink.RunInternalScriptGetValue(clsVariablesMetadataChanged.ToScript())
If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then
Return expTemp.AsLogical(0)
Expand All @@ -121,19 +127,26 @@ Public Class clsColumnMetaData
''' </summary>
Public Sub RefreshData()
'Need to check to see if dataframe exists due to the column meta data not changing when sheets are un-hidden
If _clsDataFrame Is Nothing Or HasDataChanged() Then
_clsDataFrame = GetDataFrameFromRCommand()
ResetDataFramesChanged()
If _clsColsMetadataDataFrame Is Nothing OrElse HasDataChanged() Then
_clsColsMetadataDataFrame = GetColsMetadataFromRCommand()
SetColsMetadataToNotChangedInR()

'this change number should eventually come from R
'once that is done;
'HasDataChanged() should be re-implemeted
'HasChanged property can be deleted
'SetColsMetadataToNotChangedInR() can be deleted
MetadataChangeAuditId += 1
End If
End Sub

Private Function GetDataFrameFromRCommand() As DataFrame
Private Function GetColsMetadataFromRCommand() As DataFrame
Dim clsGetVariablesMetadata As New RFunction
Dim expTemp As SymbolicExpression
_hasChanged = True
clsGetVariablesMetadata.SetRCommand(_RLink.strInstatDataObject & "$get_variables_metadata")
clsGetVariablesMetadata.AddParameter("convert_to_character", "TRUE")
clsGetVariablesMetadata.AddParameter("data_name", Chr(34) & _strName & Chr(34))
clsGetVariablesMetadata.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34))
expTemp = _RLink.RunInternalScriptGetValue(clsGetVariablesMetadata.ToScript(), bSilent:=True)
If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then
Return expTemp.AsDataFrame
Expand All @@ -142,10 +155,10 @@ Public Class clsColumnMetaData
End If
End Function

Private Sub ResetDataFramesChanged()
Private Sub SetColsMetadataToNotChangedInR()
Dim clsSetVariablesMetadataChanged As New RFunction
clsSetVariablesMetadataChanged.SetRCommand(_RLink.strInstatDataObject & "$set_variables_metadata_changed")
clsSetVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strName & Chr(34))
clsSetVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34))
clsSetVariablesMetadataChanged.AddParameter("new_val", "FALSE")
_RLink.RunInternalScript(clsSetVariablesMetadataChanged.ToScript(), bSilent:=True)
End Sub
Expand Down
82 changes: 44 additions & 38 deletions instat/Model/DataFrame/clsDataBook.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Imports RDotNet
''' </summary>
Public Class clsDataBook
Private _RLink As RLink
Private _dataFrames As List(Of clsDataFrame)
Private _lstDataFrames As List(Of clsDataFrame)
Private _clsDataFrameMetaData As clsDataFrameMetaData

''' <summary>
Expand All @@ -30,10 +30,10 @@ Public Class clsDataBook
''' <returns></returns>
Public Property DataFrames() As List(Of clsDataFrame)
Get
Return _dataFrames
Return _lstDataFrames
End Get
Set(value As List(Of clsDataFrame))
_dataFrames = value
_lstDataFrames = value
End Set
End Property
''' <summary>
Expand All @@ -53,7 +53,7 @@ Public Class clsDataBook
''' <param name="rLink"></param>
Public Sub New(rLink As RLink)
_RLink = rLink
_dataFrames = New List(Of clsDataFrame)
_lstDataFrames = New List(Of clsDataFrame)
_clsDataFrameMetaData = New clsDataFrameMetaData(rLink)
End Sub

Expand Down Expand Up @@ -86,74 +86,80 @@ Public Class clsDataBook
_RLink.RunScript(clsHideDataFrame.ToScript(), strComment:="Right click menu: Hide Data Frame")
End Sub

Private Function CreateNewGridTab(strDataFrameName As String) As clsDataFrame
Dim dataframe As New clsDataFrame(_RLink, strDataFrameName)
_dataFrames.Add(dataframe)
Return dataframe
End Function

''' <summary>
''' Gets the dataframe within the databook corresponding to the given name
''' </summary>
''' <param name="strName"></param>
''' <returns></returns>
Public Function GetDataFrame(strName As String) As clsDataFrame
Return _dataFrames.Where(Function(x) x.strName = strName).FirstOrDefault
Return _lstDataFrames.Where(Function(x) x.strName = strName).FirstOrDefault
End Function

''' <summary>
''' Gets the Column Metadata for the dataframe name given
''' </summary>
''' <param name="strName"></param>
''' <returns></returns>
Public Function GetColumnMetaData(strName As String) As clsColumnMetaData
Return _dataFrames.Where(Function(x) x.strName = strName).FirstOrDefault().clsColumnMetaData
Return _lstDataFrames.Where(Function(x) x.strName = strName).FirstOrDefault().clsColumnMetaData
End Function

''' <summary>
''' Updates all the dataframes and metadata where the data has changed
''' </summary>
Public Sub RefreshData()
'if no R Instat object exists then just clear all data frames in the databook
'and refresh the data frame metadata from R
If Not _RLink.bInstatObjectExists Then
DeleteAllDataFrames()
_lstDataFrames.Clear()
_clsDataFrameMetaData = New clsDataFrameMetaData(_RLink)
Exit Sub
End If

'else if the R Instat object data has changed
'refresh data frames data and metadata
If HasDataChanged() Then
Dim listOfDataFrames As List(Of String) = GetDataFrameNames()
DeleteOldDataFrames(listOfDataFrames)
For Each strDataFrameName In listOfDataFrames
Dim dataFrame As clsDataFrame = GetOrCreateDataFrame(strDataFrameName)
dataFrame.RefreshData()
Next
RefreshDataFrames()
_clsDataFrameMetaData.RefreshData()
End If
End Sub

Private Sub DeleteAllDataFrames()
Dim listOfDataFrames As New List(Of String)
DeleteOldDataFrames(listOfDataFrames)
End Sub
''' <summary>
''' refreshes data book with recent R data frames and the data frames with their recent R data
''' </summary>
Private Sub RefreshDataFrames()
'get the recent list of data frame names from R Instant
Dim lstOfCurrentRDataFrameNames As List(Of String) = GetDataFrameNamesFromR()

Private Function GetOrCreateDataFrame(strDataFrameName As String) As clsDataFrame
Dim dataFrame As clsDataFrame
dataFrame = _dataFrames.Where(Function(x) x.strName = strDataFrameName).SingleOrDefault
If dataFrame Is Nothing Then
dataFrame = CreateNewGridTab(strDataFrameName)
End If
Return dataFrame
End Function
'remove any data frames from this data book that are not in the R Instat object
_lstDataFrames.RemoveAll(Function(x) Not lstOfCurrentRDataFrameNames.Contains(x.strName))

Private Sub DeleteOldDataFrames(currentDataFrames As List(Of String))
Dim gridTab As clsDataFrame
For i = _dataFrames.Count - 1 To 0 Step -1
gridTab = _dataFrames(i)
If Not currentDataFrames.Contains(gridTab.strName) Then
_dataFrames.RemoveAt(i)
'add any R Instat object data frames missing in the data book
'and also refresh data of the data book data frames
Dim dataFrame As clsDataFrame
For Each strDataFrameName In lstOfCurrentRDataFrameNames
dataFrame = _lstDataFrames.Where(Function(x) x.strName = strDataFrameName).SingleOrDefault
If dataFrame Is Nothing Then
dataFrame = New clsDataFrame(_RLink, strDataFrameName)
_lstDataFrames.Add(dataFrame)
End If
'if data not refreshed successfully, remove the data frame from the data book
If Not dataFrame.RefreshData() Then
MessageBox.Show("Error: Could not retrieve data frame:" & strDataFrameName & " from R" &
Environment.NewLine & "Data displayed in spreadsheet may not be up to date." &
Environment.NewLine & "We strongly suggest restarting R-Instat before continuing.",
"Cannot retrieve data", MessageBoxButtons.OK, MessageBoxIcon.Warning)
_lstDataFrames.Remove(dataFrame)
End If
Next
End Sub

Private Function GetDataFrameNames() As List(Of String)

''' <summary>
''' Gets current data frame names from R (the R Instant object).
''' </summary>
''' <returns>list of data frame names. If no data frame names found, an empty list is returned</returns>
Private Function GetDataFrameNamesFromR() As List(Of String)
Dim clsGetDataFrameNames As New RFunction
Dim expTemp As SymbolicExpression
Dim listOfDataFrames As New List(Of String)
Expand Down
Loading

0 comments on commit 9965249

Please sign in to comment.