Skip to content

Commit

Permalink
Merge pull request #38 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
fetching latest copy of master
  • Loading branch information
maxwellfundi committed Feb 27, 2016
2 parents 79c41b3 + 5c1d607 commit 4289713
Show file tree
Hide file tree
Showing 22 changed files with 718 additions and 305 deletions.
15 changes: 9 additions & 6 deletions instat/clsGridLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Public Class clsGridLink
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim dfTemp As DataFrame
Dim dfTemp As CharacterMatrix
Dim strDataName As String
Dim shtTemp As Worksheet

Expand All @@ -51,13 +51,13 @@ Public Class clsGridLink
For i = 0 To lstDataNames.Length - 1
strDataName = lstDataNames.AsCharacter(i)
If (bGrdDataExists And frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_data_changed(data_name = " & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
frmMain.clsRLink.clsEngine.Evaluate(strDataName & "<-" & frmMain.clsRLink.strInstatDataObject & "$get_data_frame(" & Chr(34) & strDataName & Chr(34) & ")")
dfTemp = frmMain.clsRLink.clsEngine.GetSymbol(strDataName).AsDataFrame
frmMain.clsRLink.clsEngine.Evaluate(strDataName & "<-" & frmMain.clsRLink.strInstatDataObject & "$get_data_frame(" & Chr(34) & strDataName & Chr(34) & ", convert_to_character = TRUE)")
dfTemp = frmMain.clsRLink.clsEngine.GetSymbol(strDataName).AsCharacterMatrix
FillSheet(dfTemp, strDataName, grdData)
frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$set_data_frames_changed(" & Chr(34) & strDataName & Chr(34) & ", FALSE)")
End If
If (bGrdVariablesMetadataExists And frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
dfTemp = frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata(" & Chr(34) & strDataName & Chr(34) & ")").AsDataFrame
dfTemp = frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata(" & Chr(34) & strDataName & Chr(34) & ", convert_to_character = TRUE)").AsCharacterMatrix
FillSheet(dfTemp, strDataName, grdVariablesMetadata)
frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$set_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ", FALSE)")
End If
Expand Down Expand Up @@ -106,7 +106,7 @@ Public Class clsGridLink
End If

If bGrdMetadataExists And (bGrdMetadataChanged Or bRMetadataChanged) Then
dfTemp = frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_combined_metadata()").AsDataFrame
dfTemp = frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_combined_metadata(convert_to_character = TRUE)").AsCharacterMatrix
FillSheet(dfTemp, "metadata", grdMetadata)
frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$set_metadata_changed(new_val = FALSE)")
End If
Expand Down Expand Up @@ -145,10 +145,11 @@ Public Class clsGridLink
UpdateGrids()
End Sub

Public Sub FillSheet(dfTemp As DataFrame, strName As String, grdCurr As ReoGridControl)
Public Sub FillSheet(dfTemp As CharacterMatrix, strName As String, grdCurr As ReoGridControl)
Dim bFoundWorksheet As Boolean = False
Dim tempWorkSheet As Worksheet
Dim fillWorkSheet As Worksheet
Dim rngDataRange As RangePosition

For Each tempWorkSheet In grdCurr.Worksheets
If tempWorkSheet.Name = strName Then
Expand All @@ -165,6 +166,8 @@ Public Class clsGridLink
End If

fillWorkSheet.Reset()
rngDataRange = New RangePosition(0, 0, dfTemp.RowCount, dfTemp.ColumnCount)
fillWorkSheet.SetRangeDataFormat(rngDataRange, DataFormat.CellDataFormatFlag.Text)
fillWorkSheet.Rows = dfTemp.RowCount
fillWorkSheet.Columns = dfTemp.ColumnCount
For i As Integer = 0 To dfTemp.RowCount - 1
Expand Down
7 changes: 4 additions & 3 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ Public Class RLink
End Sub


Public Function GetData(strLabel As String) As DataFrame
Public Function GetData(strLabel As String) As CharacterMatrix

Me.clsEngine.Evaluate("temp<-" & strLabel).AsDataFrame()
Return Me.clsEngine.GetSymbol("temp").AsDataFrame()
Me.clsEngine.Evaluate("temp<-" & strLabel)
Me.clsEngine.Evaluate("temp <- convert_to_character_matrix(temp)")
Return Me.clsEngine.GetSymbol("temp").AsCharacterMatrix()

End Function

Expand Down
2 changes: 1 addition & 1 deletion instat/dlgCalculator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Public Class dlgCalculator
Dim strScript As String
strScript = ("data[[" & Chr(34) & txtNewColumnName.Text & Chr(34) & "]]" & " <- " & txtCalcLine.Text).ToString
frmMain.clsRLink.RunScript(strScript)
dataset = frmMain.clsRLink.GetData("data")
'dataset = frmMain.clsRLink.GetData("data")
'frmEditor.UpdateSheet(dataset)
End Sub

Expand Down
182 changes: 146 additions & 36 deletions instat/dlgConvertColumnsToFactors.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions instat/dlgConvertColumnsToFactors.vb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,92 @@
'
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports instat.Translations

Public Class dlgConvertColumnsToFactors
Public bFirstLoad As Boolean = True

Private Sub ucrSelectorDataFrameColumns_Load(sender As Object, e As EventArgs) Handles ucrSelectorDataFrameColumns.Load
ucrBase.clsRsyntax.SetFunction(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type")

ucrReceiverColumnsToConvert.Selector = ucrSelectorDataFrameColumns
autoTranslate(Me)
ucrBase.iHelpTopicID = 34

If bFirstLoad Then
SetDefaults()
bFirstLoad = False

End If

TestOKEnabled()

End Sub

Private Sub SetDefaults()
ucrSelectorDataFrameColumns.Reset()
ucrSelectorDataFrameColumns.Focus()
ucrReceiverColumnsToConvert.SetMeAsReceiver()
rdoFactor.Checked = True


TestOKEnabled()
End Sub

Private Sub ucrSelectorDataFrameolumns_DataFrameChanged() Handles ucrSelectorDataFrameColumns.DataFrameChanged
ucrBase.clsRsyntax.AddParameter("data_name", Chr(34) & ucrSelectorDataFrameColumns.ucrAvailableDataFrames.cboAvailableDataFrames.SelectedItem & Chr(34))

End Sub

Private Sub ucrReceiverColumnsToConvert_SelectionChanged() Handles ucrReceiverColumnsToConvert.SelectionChanged
ucrBase.clsRsyntax.AddParameter("col_names", ucrReceiverColumnsToConvert.GetVariableNames)
TestOKEnabled()
End Sub

Private Sub grpForConvertToType_CheckedChanged(sender As Object, e As EventArgs) Handles rdoFactor.CheckedChanged, rdoNumeric.CheckedChanged, rdoCharacter.CheckedChanged, rdoInteger.CheckedChanged
If rdoFactor.Checked Then
grpFactorNumeric.Visible = True
ucrBase.clsRsyntax.AddParameter("to_type", Chr(34) & "factor" & Chr(34))
TestOKEnabled()

ElseIf rdoNumeric.Checked Then
grpFactorNumeric.Visible = False
ucrBase.clsRsyntax.AddParameter("to_type", Chr(34) & "numeric" & Chr(34))
TestOKEnabled()
ElseIf rdoCharacter.Checked Then
grpFactorNumeric.Visible = False
ucrBase.clsRsyntax.AddParameter("to_type", Chr(34) & "character" & Chr(34))
TestOKEnabled()
ElseIf rdoInteger.Checked Then
grpFactorNumeric.Visible = False
ucrBase.clsRsyntax.AddParameter("to_type", Chr(34) & "integer" & Chr(34))
TestOKEnabled()
Else
ucrBase.clsRsyntax.RemoveParameter("to_type")
grpFactorNumeric.Visible = False

'the else case should never happen but is there just in case
End If
End Sub

Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
TestOKEnabled()

End Sub


Private Sub TestOKEnabled()
If ucrReceiverColumnsToConvert.IsEmpty() = False And (rdoFactor.Checked = True Or rdoNumeric.Checked = True Or rdoCharacter.Checked = True Or rdoInteger.Checked = True) Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If
End Sub

Private Sub cboFactorNumeric_SelectedValueChanged(sender As Object, e As EventArgs) Handles cboFactorNumeric.SelectedValueChanged

ucrBase.clsRsyntax.AddParameter("factor_numeric", cboFactorNumeric.SelectedItem.ToString)

End Sub
End Class
Loading

0 comments on commit 4289713

Please sign in to comment.