Skip to content

Commit

Permalink
Merge pull request #5978 from Patowhiz/NewImportDialogChanges
Browse files Browse the repository at this point in the history
Importing .dly files, text files with multiple missing values and resetting select all checkbox
  • Loading branch information
lloyddewit authored Nov 5, 2020
2 parents 95d73b4 + 1b824ff commit 32bf110
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
4 changes: 3 additions & 1 deletion instat/clsGridLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ Public Class clsGridLink
End If
Next
Else
For k = 0 To lstColumnNames.Count - 1
'worksheet columns could be less than than the data frame columns,
'so use worksheet ColumnCount
For k = 0 To fillWorkSheet.ColumnCount - 1
fillWorkSheet.ColumnHeaders(k).Text = lstColumnNames(k)
Next
End If
Expand Down
41 changes: 28 additions & 13 deletions instat/dlgImportDataset.vb
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ Public Class dlgImportDataset
ucrChkColumnNamesText.SetParameter(New RParameter("col_names"), bNewChangeParameterValue:=True, bNewAddRemoveParameter:=True, strNewValueIfChecked:="TRUE", strNewValueIfUnchecked:="FALSE")
ucrChkColumnNamesText.SetRDefault("TRUE")

ucrInputMissingValueStringText.SetParameter(New RParameter("na"))
ucrInputMissingValueStringText.SetRDefault(Chr(34) & "NA" & Chr(34))

ucrNudRowsToSkipText.SetParameter(New RParameter("skip"))
ucrNudRowsToSkipText.Minimum = 0
ucrNudRowsToSkipText.SetRDefault(0)
Expand Down Expand Up @@ -386,6 +383,12 @@ Public Class dlgImportDataset
strFilePathR = ""
strFileType = ""

dctSelectedExcelSheets.Clear()
clbSheets.Items.Clear() 'reset this here. Not set by R code
ucrInputMissingValueStringExcel.SetName("") 'reset this here. Not set by R code
ucrInputMissingValueStringCSV.SetName("") 'reset this here. Not set by R code
ucrInputMissingValueStringText.SetName("") 'reset this here. Not set by R code

ucrNudPreviewLines.Value = 10

ucrPanelFixedWidthText.Hide()
Expand Down Expand Up @@ -413,9 +416,6 @@ Public Class dlgImportDataset
SetDefaults()
SetRCodeForControls(True)
RefreshFrameView()
dctSelectedExcelSheets.Clear()
clbSheets.Items.Clear() 'reset this here. Not set by R code
ucrInputMissingValueStringExcel.SetText("") 'reset this here. Not set by R code
TestOkEnabled()
End Sub

Expand All @@ -434,7 +434,7 @@ Public Class dlgImportDataset
'Loads the open dialog on load and click
Public Sub GetFileFromOpenDialog()
Using dlgOpen As New OpenFileDialog
dlgOpen.Filter = "All Data files|*.csv;*.txt;*.xls;*.xlsx;*.RDS;*.sav;*.tsv;*.csvy;*.feather;*.psv;*.RData;*.json;*.yml;*.dta;*.dbf;*.arff;*.R;*.sas7bdat;*.xpt;*.mtp;*.rec;*.syd;*.dif;*.ods;*.xml;*.html|Comma separated files|*.csv|Text data file|*.txt|Excel files|*.xls;*.xlsx|R Data Structure files|*.RDS|SPSS files|*.sav|Tab separated files|*.tsv|CSV with a YAML metadata header|*.csvy|Feather R/Python interchange format|*.feather|Pipe separates files|*.psv|Saved R objects|*.RData|JSON|*.json|YAML|*.yml|Stata files|*.dta|XBASE database files|*.dbf|Weka Attribute-Relation File Format|*.arff|R syntax object|*.R|SAS Files|*.sas7bdat|SAS XPORT|*.xpt|Minitab Files|*.mtp|Epiinfo Files|*.rec|Systat Files|*.syd|Data Interchange Format|*.dif|OpenDocument Spreadsheet|*.ods|Shallow XML documents|*.xml|Single-table HTML documents|*.html;|All files|*.*;"
dlgOpen.Filter = "All Data files|*.csv;*.txt;*.xls;*.xlsx;*.RDS;*.sav;*.tsv;*.csvy;*.feather;*.psv;*.RData;*.json;*.yml;*.dta;*.dbf;*.arff;*.R;*.sas7bdat;*.xpt;*.mtp;*.rec;*.syd;*.dif;*.ods;*.xml;*.html;*.dly|Comma separated files|*.csv|Text data file|*.txt|Excel files|*.xls;*.xlsx|R Data Structure files|*.RDS|SPSS files|*.sav|Tab separated files|*.tsv|CSV with a YAML metadata header|*.csvy|Feather R/Python interchange format|*.feather|Pipe separates files|*.psv|Saved R objects|*.RData|JSON|*.json|YAML|*.yml|Stata files|*.dta|XBASE database files|*.dbf|Weka Attribute-Relation File Format|*.arff|R syntax object|*.R|SAS Files|*.sas7bdat|SAS XPORT|*.xpt|Minitab Files|*.mtp|Epiinfo Files|*.rec|Systat Files|*.syd|Data Interchange Format|*.dif|OpenDocument Spreadsheet|*.ods|Shallow XML documents|*.xml|Single-table HTML documents|*.html|DLY|*.dly|All files|*.*"
dlgOpen.Multiselect = False
If bFromLibrary Then
dlgOpen.Title = "Import from Library"
Expand Down Expand Up @@ -498,7 +498,6 @@ Public Class dlgImportDataset
ucrPanelFixedWidthText.SetRCode(ucrBase.clsRsyntax.clsBaseFunction, bReset)
'TEXT CONTROLS
ucrChkColumnNamesText.SetRCode(clsImportFixedWidthText, bReset)
ucrInputMissingValueStringText.SetRCode(clsImportFixedWidthText, bReset)
ucrNudRowsToSkipText.SetRCode(clsImportFixedWidthText, bReset)
ucrNudMaxRowsText.SetRCode(clsImportFixedWidthText, bReset)
ucrChkMaxRowsText.SetRCode(clsImportFixedWidthText, bReset)
Expand Down Expand Up @@ -600,14 +599,18 @@ Public Class dlgImportDataset
grpRDS.Show()
ElseIf strFileExt = ".txt" Then
strFileType = "TXT"
'add or change format parameter values
clsImportCSV.AddParameter("format", Chr(34) & "txt" & Chr(34), iPosition:=1)
'by default the textfiles will be imported using the function we use for csv
ucrBase.clsRsyntax.SetBaseRFunction(clsImportCSV)
ucrPanelFixedWidthText.Show()
grpCSV.Text = "Import Text Options"
grpCSV.Location = New System.Drawing.Point(9, 99) 'set the location of the groupbox to adjust gaps in the form UI
grpCSV.Show()
ElseIf strFileExt = ".csv" Then
ElseIf strFileExt = ".csv" OrElse strFileExt = ".dly" Then
strFileType = "CSV"
'add format. forces rio to treat dly files as csv
clsImportCSV.AddParameter("format", Chr(34) & "csv" & Chr(34), iPosition:=1)
ucrBase.clsRsyntax.SetBaseRFunction(clsImportCSV)
grpCSV.Text = "Import CSV Options"
grpCSV.Location = New System.Drawing.Point(9, 50) 'set the location of the groupbox to adjust gaps in the form UI
Expand Down Expand Up @@ -700,13 +703,12 @@ Public Class dlgImportDataset
If {"TXT", "CSV", "XLSX", "XLS"}.Contains(strFileType) AndAlso Not ucrInputFilePath.IsEmpty() Then
If strFileType = "TXT" Then
If rdoSeparatortext.Checked Then
'for separtor we use the function used for csv
'for separator we use the function used for csv
clsTempImport = clsImportCSV.Clone()
strRowMaxParamName = "nrows"
Else
clsTempImport = clsImportFixedWidthText.Clone()
strRowMaxParamName = "n_max"
clsTempImport.AddParameter("na", Chr(34) & ucrInputMissingValueStringText.GetText & Chr(34))
End If

ElseIf strFileType = "CSV" Then
Expand Down Expand Up @@ -826,13 +828,19 @@ Public Class dlgImportDataset
For Each strSelected As String In lstCheckedItems
For i As Integer = 0 To clbSheets.Items.Count - 1
If strSelected = clbSheets.Items(i).ToString Then
bSupressSheetChange = True
clbSheets.SetItemChecked(i, True)
bSupressSheetChange = False
'sheet names are expected to be unique so exit inner for loop
Exit For
End If
Next
Next
End If
'set checked status of select all checkbox
bSupressCheckAllSheets = True
ucrChkSheetsCheckAll.Checked = chrSheets IsNot Nothing AndAlso clbSheets.CheckedItems.Count = chrSheets.Count
bSupressCheckAllSheets = False
End Sub

Private Sub lblRowVector_Click(sender As Object, e As EventArgs)
Expand Down Expand Up @@ -865,7 +873,7 @@ Public Class dlgImportDataset
RefreshFrameView()
End Sub

Private Sub Controls_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkTrimWSExcel.ControlValueChanged, ucrNudRowsToSkipExcel.ControlValueChanged, ucrChkColumnNamesExcel.ControlValueChanged, ucrChkColumnNamesText.ControlValueChanged, ucrNudRowsToSkipText.ControlValueChanged, ucrChkMaxRowsText.ControlValueChanged, ucrChkMaxRowsCSV.ControlValueChanged, ucrChkMaxRowsExcel.ControlValueChanged, ucrNudMaxRowsText.ControlValueChanged, ucrNudMaxRowsCSV.ControlValueChanged, ucrNudMaxRowsExcel.ControlValueChanged, ucrChkStringsAsFactorsCSV.ControlValueChanged, ucrInputMissingValueStringCSV.ControlValueChanged, ucrInputEncodingCSV.ControlValueChanged, ucrInputSeparatorCSV.ControlValueChanged, ucrInputHeadersCSV.ControlValueChanged, ucrInputDecimalCSV.ControlValueChanged, ucrNudRowsToSkipCSV.ControlValueChanged
Private Sub Controls_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkTrimWSExcel.ControlValueChanged, ucrNudRowsToSkipExcel.ControlValueChanged, ucrChkColumnNamesExcel.ControlValueChanged, ucrChkColumnNamesText.ControlValueChanged, ucrNudRowsToSkipText.ControlValueChanged, ucrChkMaxRowsText.ControlValueChanged, ucrChkMaxRowsCSV.ControlValueChanged, ucrChkMaxRowsExcel.ControlValueChanged, ucrNudMaxRowsText.ControlValueChanged, ucrNudMaxRowsCSV.ControlValueChanged, ucrNudMaxRowsExcel.ControlValueChanged, ucrChkStringsAsFactorsCSV.ControlValueChanged, ucrInputEncodingCSV.ControlValueChanged, ucrInputSeparatorCSV.ControlValueChanged, ucrInputHeadersCSV.ControlValueChanged, ucrInputDecimalCSV.ControlValueChanged, ucrNudRowsToSkipCSV.ControlValueChanged
RefreshFrameView()
End Sub

Expand All @@ -877,7 +885,14 @@ Public Class dlgImportDataset
clsImportExcelMulti.AddParameter("na", GetMissingValueRString(ucrInputMissingValueStringExcel.GetText()))
clsImportExcel.AddParameter("na", GetMissingValueRString(ucrInputMissingValueStringExcel.GetText()))
ElseIf strFileType = "CSV" Then
clsImportCSV.AddParameter("na.strings", GetMissingValueRString(ucrInputMissingValueStringCSV.GetText()))
clsImportCSV.AddParameter("na.strings", GetMissingValueRString(ucrInputMissingValueStringCSV.GetText()), iPosition:=2)
ElseIf strFileType = "TXT" Then
'for separator we use the function used for csv
If rdoSeparatortext.Checked Then
clsImportCSV.AddParameter("na.strings", GetMissingValueRString(ucrInputMissingValueStringCSV.GetText()), iPosition:=2)
Else
clsImportFixedWidthText.AddParameter("na", GetMissingValueRString(ucrInputMissingValueStringText.GetText()), iPosition:=2)
End If
End If
RefreshFrameView()
End Sub
Expand Down

0 comments on commit 32bf110

Please sign in to comment.