private void mnuItemDefFactors_Click(object sender, EventArgs e)
        {
            var tmpDatasets = MakeDeepCopy(marrDatasetInfo); // keep copies
            var tmpFactors = MakeDeepCopy(marrFactorInfo); // keep copies

            var mstrFrom = sender.ToString();

            if (!mhtDatasets.ContainsKey("Factors"))
            {
                if (!ValidateExpressionsLoaded("define factors; load some data using File->Open"))
                {
                    return;
                }
            }

            var mfrmFactorInfo = new frmFactorInformation
            {
                DatasetInfo = marrDatasetInfo,
                FactorsLoaded = mhtDatasets.ContainsKey("Factors"),
                FactorInfo = marrFactorInfo
            };

            if (mstrFrom.Equals("Arrange Columns"))
            {
                mfrmFactorInfo.OrderChangeOnly = true;
                mfrmFactorInfo.Title = "Dataset Order";
                mfrmFactorInfo.SubTitle = "Change Dataset Order, Delete Datasets";
                mfrmFactorInfo.WinTitle = "Dataset Order";
            }
            if (mfrmFactorInfo.ShowDialog() == DialogResult.OK)
            {
                marrDatasetInfo = mfrmFactorInfo.DatasetInfo;
                if (mfrmFactorInfo.OrderChanged)
                {
                    ChangeDatasetOrder(mfrmFactorInfo.NewDatasetNameOrder);
                    ChangeDatasetOrderR(mfrmFactorInfo.NewDatasetOrder);
                }
                marrFactorInfo = mfrmFactorInfo.FactorInfo;
                if (marrFactorInfo.Count > 0)
                {
                    var mDTFactors = DatasetArr2DT();
                    mDTFactors.Columns[0].ColumnName = "Factors";
                    mDTFactors.TableName = "factors";
                    AddDataset2HashTable(mDTFactors);
                    if (mhtDatasets.ContainsKey("Factors"))
                    {
                        AddDataNode(mhtDatasets["Factors"]);
                    }

                    if (mRConnector.SendTable2RmatrixNonNumeric("factors", mDTFactors))
                    {
                        try
                        {
                            mRConnector.EvaluateNoReturn("print(factors)");
                            mRConnector.EvaluateNoReturn("cat(\"Factors loaded.\n\")");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message, "Exception while talking to R");
                        }
                    }
                }
            }
            else //User cancels the factor changes, so revert to previous.
            {
                marrDatasetInfo = tmpDatasets; //Should we do a DeepCopy here?
                marrFactorInfo = tmpFactors;
            }
        }
Esempio n. 2
0
        private void mnuItemDefFactors_Click(object sender, EventArgs e)
        {
            var tmpDatasets = MakeDeepCopy(marrDatasetInfo); // keep copies
            var tmpFactors  = MakeDeepCopy(marrFactorInfo);  // keep copies

            var mstrFrom = sender.ToString();

            if (!mhtDatasets.ContainsKey("Factors"))
            {
                if (!ValidateExpressionsLoaded("define factors; load some data using File->Open"))
                {
                    return;
                }
            }

            var mfrmFactorInfo = new frmFactorInformation
            {
                DatasetInfo   = marrDatasetInfo,
                FactorsLoaded = mhtDatasets.ContainsKey("Factors"),
                FactorInfo    = marrFactorInfo
            };

            if (mstrFrom.Equals("Arrange Columns"))
            {
                mfrmFactorInfo.OrderChangeOnly = true;
                mfrmFactorInfo.Title           = "Dataset Order";
                mfrmFactorInfo.SubTitle        = "Change Dataset Order, Delete Datasets";
                mfrmFactorInfo.WinTitle        = "Dataset Order";
            }
            if (mfrmFactorInfo.ShowDialog() == DialogResult.OK)
            {
                marrDatasetInfo = mfrmFactorInfo.DatasetInfo;
                if (mfrmFactorInfo.OrderChanged)
                {
                    ChangeDatasetOrder(mfrmFactorInfo.NewDatasetNameOrder);
                    ChangeDatasetOrderR(mfrmFactorInfo.NewDatasetOrder);
                }
                marrFactorInfo = mfrmFactorInfo.FactorInfo;
                if (marrFactorInfo.Count > 0)
                {
                    var mDTFactors = DatasetArr2DT();
                    mDTFactors.Columns[0].ColumnName = "Factors";
                    mDTFactors.TableName             = "factors";
                    AddDataset2HashTable(mDTFactors);
                    if (mhtDatasets.ContainsKey("Factors"))
                    {
                        AddDataNode(mhtDatasets["Factors"]);
                    }

                    if (mRConnector.SendTable2RmatrixNonNumeric("factors", mDTFactors))
                    {
                        try
                        {
                            mRConnector.EvaluateNoReturn("print(factors)");
                            mRConnector.EvaluateNoReturn("cat(\"Factors loaded.\n\")");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message, "Exception while talking to R");
                        }
                    }
                }
            }
            else //User cancels the factor changes, so revert to previous.
            {
                marrDatasetInfo = tmpDatasets; //Should we do a DeepCopy here?
                marrFactorInfo  = tmpFactors;
            }
        }