Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#4322 from Patowhiz/NewDataFrame…
Browse files Browse the repository at this point in the history
…Error

New Data Frame Error
  • Loading branch information
dannyparsons authored Jan 19, 2018
2 parents 3393fa6 + e363d89 commit dfee45d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
27 changes: 13 additions & 14 deletions instat/dlgNewDataFrame.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports instat
Imports instat.Translations
Imports RDotNet

Public Class dlgNewDataFrame
Private clsOverallFunction, clsMatrixFunction As New RFunction
Public bFirstLoad As Boolean = True
Private bReset As Boolean = True

Private Sub dlgNewDataFrame_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)
If bFirstLoad Then
InitialiseDialog()
bFirstLoad = False
Expand All @@ -33,18 +32,19 @@ Public Class dlgNewDataFrame
End If
SetRCodeforControls(bReset)
bReset = False
'autoTranslate(Me)
'temporary fix for autoTranslate(Me) which overwrites the label text to Label1
ucrNewDFName.SetLabelText("New Data Frame Name:")
End Sub

Private Sub InitialiseDialog()
ucrBase.iHelpTopicID = 6

'nudRows
ucrNudRows.SetParameter(New RParameter("nrow"))
ucrNudRows.SetParameter(New RParameter("nrow", iNewPosition:=1))
ucrNudRows.SetMinMax(1, Integer.MaxValue)

'nudCols
ucrNudCols.SetParameter(New RParameter("ncol"))
ucrNudCols.SetParameter(New RParameter("ncol", iNewPosition:=2))
ucrNudCols.SetMinMax(1, Integer.MaxValue)

' ucrNewSheetName
Expand All @@ -61,23 +61,22 @@ Public Class dlgNewDataFrame
End Sub

Private Sub SetDefaults()
Dim clsMatrixDefaultFunction As New RFunction
clsOverallFunction = New RFunction
clsMatrixFunction = New RFunction

ucrNewDFName.Reset()

' Default R
'e.g of Function to be constructed . data.frame(data=matrix(data = NA,nrow = 10, ncol = 2))
clsOverallFunction.SetRCommand("data.frame")

'matrix(nrow = 10, ncol = 2, Data = NA)
clsMatrixDefaultFunction.SetRCommand("matrix")
clsMatrixDefaultFunction.AddParameter("data", "NA")
clsMatrixDefaultFunction.AddParameter("ncol", 2)
clsMatrixDefaultFunction.AddParameter("nrow", 10)
'matrix(data = NA,nrow = 10, ncol = 2)
clsMatrixFunction.SetRCommand("matrix")
clsMatrixFunction.AddParameter("data", "NA", iPosition:=0)
clsMatrixFunction.AddParameter("nrow", 10, iPosition:=1)
clsMatrixFunction.AddParameter("ncol", 2, iPosition:=2)

clsOverallFunction.AddParameter("data", clsRFunctionParameter:=clsMatrixFunction, iPosition:=0)
ucrBase.clsRsyntax.SetBaseRFunction(clsOverallFunction)
clsMatrixFunction = clsMatrixDefaultFunction.Clone()
clsOverallFunction.AddParameter("data", clsRFunctionParameter:=clsMatrixFunction)
End Sub

Private Sub TestOKEnabled()
Expand Down
11 changes: 10 additions & 1 deletion instat/static/InstatObject/R/data_object_R6.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,16 @@ data_object$set("public", "get_data_frame", function(convert_to_character = FALS
}
}
if(!missing(max_cols) && max_cols < ncol(out)) out <- out[1:max_cols]
if(!missing(max_rows) && max_rows < nrow(out)) out <- out[1:max_rows, ]
if(!missing(max_rows) && max_rows < nrow(out)) {
#for data frames with 1 col use slice because out[1:max_rows, ] will return a vector
if(ncol(out) == 1){
rnames <- row.names(out)[1:max_rows]
out <- as.data.frame(dplyr::slice(out,1:max_rows))
row.names(out) <- rnames
} else {
out <- out[1:max_rows, ]
}
}
if(convert_to_character) {
decimal_places = self$get_variables_metadata(property = signif_figures_label, column = names(out), error_if_no_property = FALSE)
decimal_places[is.na(decimal_places)] <- 0
Expand Down

0 comments on commit dfee45d

Please sign in to comment.