Skip to content

Commit

Permalink
Merge pull request #45 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating master
  • Loading branch information
shadrackkibet authored Sep 19, 2017
2 parents 384b928 + c7635eb commit 7518074
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 20 deletions.
16 changes: 16 additions & 0 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,22 @@ Public Class RLink
Return strColumn
End Function

Public Function GetCorruptionComponentsColumnNames(strDataName As String) As String()
Dim clsGetComponents As New RFunction
Dim strColumn() As String
Dim expColumn As SymbolicExpression

clsGetComponents.SetRCommand(strInstatDataObject & "$get_CRI_component_column_names")
clsGetComponents.AddParameter("data_name", Chr(34) & strDataName & Chr(34))
expColumn = RunInternalScriptGetValue(clsGetComponents.ToScript(), bSilent:=True)
If expColumn IsNot Nothing AndAlso Not expColumn.Type = Internals.SymbolicExpressionType.Null Then
strColumn = expColumn.AsCharacter.ToArray
Else
strColumn = Nothing
End If
Return strColumn
End Function

Public Function GetClimaticColumnOfType(strDataName As String, strType As String) As String
Dim clsGetColumnName As New RFunction
Dim strColumn As String
Expand Down
18 changes: 18 additions & 0 deletions instat/dlgCorrelation.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Public Class dlgCorrelation
Private clsCorrelationTestFunction, clsRGGcorrGraphicsFunction, clsRGraphicsFuction, clsRGGscatMatrixFunction, clsCorrelationFunction, clsRTempFunction, clsTempFunc As New RFunction
Private clsColFunction As String
Private bResetSubdialog As Boolean = False
Public strDefaultDataFrame As String = ""
Public strDefaultColumns() As String = Nothing

Private Sub dlgCorrelation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstload Then
InitialiseDialog()
Expand All @@ -33,6 +36,7 @@ Public Class dlgCorrelation
bReset = False
autoTranslate(Me)
ReopenDialog()
SetDefaultColumn()
TestOKEnabled()
End Sub

Expand Down Expand Up @@ -176,6 +180,20 @@ Public Class dlgCorrelation
ucrSaveModel.SetRCode(clsCorrelationFunction, bReset)
End Sub

Private Sub SetDefaultColumn()
If strDefaultDataFrame <> "" Then
ucrSelectorCorrelation.SetDataframe(strDefaultDataFrame)
rdoMultipleColumns.Checked = True
End If
If strDefaultColumns IsNot Nothing AndAlso strDefaultColumns.Count > 0 Then
For Each strVar As String In strDefaultColumns
ucrReceiverMultipleColumns.Add(strVar, strDefaultDataFrame)
Next
End If
strDefaultDataFrame = ""
strDefaultColumns = Nothing
End Sub

Public Sub TestOKEnabled()
If rdoTwoColumns.Checked Then
ucrBase.clsRsyntax.RemoveAssignTo()
Expand Down
46 changes: 27 additions & 19 deletions instat/frmMain.Designer.vb

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

18 changes: 18 additions & 0 deletions instat/frmMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1657,4 +1657,22 @@ Public Class frmMain
Private Sub PlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PlToolStripMenuItem.Click
dlgPlotRegion.ShowDialog()
End Sub

Private Sub CorrelationsRedFlagsorOthersToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CorrelationsRedFlagsorOthersToolStripMenuItem.Click
Dim lstDataNames As List(Of String)
Dim strComponentColumnNames() As String

lstDataNames = clsRLink.GetCorruptionContractDataFrameNames()
If lstDataNames.Count > 0 Then
dlgCorrelation.strDefaultDataFrame = lstDataNames(0)
strComponentColumnNames = clsRLink.GetCorruptionComponentsColumnNames(lstDataNames(0))
If strComponentColumnNames IsNot Nothing AndAlso strComponentColumnNames.Count > 0 Then
dlgCorrelation.strDefaultColumns = strComponentColumnNames
End If
Else
dlgCorrelation.strDefaultDataFrame = ""
dlgCorrelation.strDefaultColumns = Nothing
End If
dlgCorrelation.ShowDialog()
End Sub
End Class
21 changes: 20 additions & 1 deletion instat/static/InstatObject/R/data_object_R6.R
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ data_object$set("public", "convert_column_to_type", function(col_names = c(), to
stop("to_type must be a character of length one")
}

if(!(to_type %in% c("integer", "factor", "numeric", "character", "ordered_factor"))) {
if(!(to_type %in% c("integer", "factor", "numeric", "character", "ordered_factor", "logical"))) {
stop(to_type, " is not a valid type to convert to")
}

Expand Down Expand Up @@ -1146,6 +1146,11 @@ data_object$set("public", "convert_column_to_type", function(col_names = c(), to
else if(to_type == "character") {
new_col <- sjmisc::to_character(curr_col)
}
else if(to_type == "logical") {
if(is.logical.like(curr_col)) new_col <- as.logical(curr_col)
else stop("Column is not numeric or contains values other than 0 and 1. Converting to logical would result in losing information.")
}

self$add_columns_to_data(col_name = col_name, col_data = new_col)

if(keep_attr) {
Expand Down Expand Up @@ -2557,6 +2562,20 @@ data_object$set("public","is_corruption_type_present", function(type) {
}
)

instat_object$set("public","get_CRI_component_column_names", function(data_name) {
self$get_data_objects(data_name)$get_CRI_component_column_names()
}
)

data_object$set("public","get_CRI_component_column_names", function() {
include <- list(TRUE)
names(include) <- corruption_index_label
return(self$get_column_names(include = include))
}
)

corruption_index_label

instat_object$set("public","get_CRI_column_names", function(data_name) {
self$get_data_objects(data_name)$get_CRI_column_names()
}
Expand Down
6 changes: 6 additions & 0 deletions instat/static/InstatObject/R/stand_alone_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ import_from_iri <- function(download_from, data_file, path, X1, X2,Y1,Y2, get_ar
return(list(dataout,lat_lon_dataframe))
}

is.logical.like <- function(x) {
if(is.logical(x)) return(TRUE)
else if(is.numeric(x)) return(all(na.omit(x) %in% c(1,0)))
else return(FALSE)
}

is.binary <- function(x) {
if(is.logical(x)) return(TRUE)
else if(is.numeric(x)) return(all(na.omit(x) %in% c(1,0)))
Expand Down

0 comments on commit 7518074

Please sign in to comment.