Skip to content

Added another button at the top, a last button called Format on the Transform Dialogue#9896

Open
bayakarisa wants to merge 12 commits intoIDEMSInternational:masterfrom
bayakarisa:format
Open

Added another button at the top, a last button called Format on the Transform Dialogue#9896
bayakarisa wants to merge 12 commits intoIDEMSInternational:masterfrom
bayakarisa:format

Conversation

@bayakarisa
Copy link
Collaborator

Partly Fixes #9721
The structure of this button is very similar to numeric. There are 8 radio buttons. They are as follows:

Decimals
Scientific
Percent
NA
Zero
P-value
Fraction
Align

image

Decimals has an up-down from -10 to 22 with default 3.
Scientific has an up-down from 0 to 22 with default 4
Percent has an nup-down from 0 to 5 with default of 2
NA has a pull down into which you can optionally type what you want. Values in the pull down are na, NA, . (i.e. dot), --, missing
Zero has a pull down where you can type if needed. In the pull down have 0, dot, -- and .
p-value this is a pull down with default p, also possible are * and p*.
Fractions has a pull down into which you can type a posuituve number. Default is 10 and you also have 20 and 100 there.
Align has a pull down into which you can type. Values are dot, e, left, center, right.

@rdstern @lilyclements @Ag-Derek I have implemented what was discussed
I'll need help putting the R functions of the buttons

The structure of this button is very similar to numeric. There are 8 radio buttons. They are as follows:

Decimals
Scientific
Percent
NA
Zero
P-value
Fraction
Align
@lilyclements
Copy link
Contributor

@bayakarisa nice!

A small comment - we only want the controls associated with that radio button (e.g., the NUD for decimals) to be visible if that radio button is selected. So we shouldn't be able to see the "Scientific" NUD or the "Percent" NUD when "Decimals" is checked.
This is probably known to you, and because the R code isn't yet set up you just hadn't set up that side yet. But I just wanted to say it in case (the function to do this is with AddToLinkedControls, you can see in the initialise in sdgPLModelOptions for an example)

I'll comment on the R code on the issue, as I'd like some clarity from @rdstern

@lilyclements
Copy link
Contributor

lilyclements commented Jul 16, 2025

@bayakarisa this uses the R function DescTools::Format

E.g., if you want to see in R:

?DescTools::Format
x <- pi * 10^(-10:10)

DescTools::Format(x, fmt="%")
  • << variable name >> - this is the name of the variable in the selector.
    There are two options with a column receiver: You can either do
ucrReceiver NAME.SetParameterIsString()

or

ucrReceiverNAME.SetParameterIsRFunction()

@bayakarisa why don't you try them both out, and see what happens in the R code for each one? (Hint: Print to script, and look at the x = VARIABLE NAME R code. It should be different depending if you set as string vs set as R function)

I've put in the issue here the R parameters and values for this function

@rdstern
Copy link
Collaborator

rdstern commented Jul 20, 2025

@bayakarisa just to add to @lilyclements comments:

a) Here is the "old" dialog:

image

In comparison, you have made the dialog quite a lot wider, just to have the quite spacious radio buttons at the top. I don't mind it a touch wider than before, but can you make the top radio buttons a bit smaller so it is not much changed from before?

Note that all the options are (I think) already working in the Transform keyboard of the calculator. This should help you with the appropriate R code as the 2 ways should be consistent. (And you can check they are working in Transform by trying them also in the calculator.

@rdstern
Copy link
Collaborator

rdstern commented Aug 4, 2025

@bayakarisa I noite nothing has happened here for 2 weeks and there is no reply from you, on your plans. Should this be passed to someone else?

@bayakarisa
Copy link
Collaborator Author

@rdstern I am still stuck with inserting the functions but derrick is helping so i might make a pull request tomorrow

@bayakarisa
Copy link
Collaborator Author

@rdstern

  1. Now only the controls associated with a specific radio button (e.g., the NUD for decimals) are visible if that radio button is selected.
Format 2. I need help here with inserting the functionality of the radio buttons e.g....

This is the current script for decimal :

Format(.x, digits=3)
data_book$append_to_variables_metadata(data_name="survey", col_names="size1", property="labels", new_val="")

It should be like this

size <- data_book$get_columns_from_data(data_name="survey", col_names="size", use_current_filter=FALSE)
size1 <- round(size)
data_book$add_columns_to_data(data_name="survey", col_name="size1", col_data=size1, before=FALSE, adjacent_column="size")

data_book$append_to_variables_metadata(data_name="survey", col_names="size1", property="labels", new_val="")
rm(list=c("size1", "size"))

@lilyclements
Copy link
Contributor

@bayakarisa

  1. I see you want to have this line:
size <- data_book$get_columns_from_data(data_name="survey", col_names="size", use_current_filter=FALSE)

This line can come automatically depending on how you set up the receiver type. There are two options with a column receiver: You can either do

ucrReceiverNAME.SetParameterIsString()

or

r
ucrReceiverNAME.SetParameterIsRFunction()

@bayakarisa why don't you try them both out, and see what happens in the R code for each one? (Hint: Print to script, and look at the x = VARIABLE NAME R code. It should be different depending if you set as string vs set as R function)

  1. You're saying as well that you want to run like this:
size1 <- round(size)

See here for the different options that you want to have. These are all in the function Format in the DescTools package.

So, for your first option, "decimals", you want to have

size1 <- DescTools::Format(size, digits = VALUE IN NUD)

For this, you therefore want to have

a. You create a class, and set the function to be Format
b. For your class, you want the package name to be DescTools
c. For your class, you have two parameters here: First, size is the name of the variable in the receiver (check the parameter name for this)
d. Second parameter is digits, with the value in the associated NUD.
e. You then want to assign this to the ucrSave.

@bayakarisa
Copy link
Collaborator Author

bayakarisa commented Aug 22, 2025

@lilyclements I have Implemented what you asked
Kindly check @berylwaswa

1. I used the Survey data set and used size

Format1

2. Here is the script that is generated it and uses the DescTools::Format

Format2

3. Here is the result - size1 its in 5 decimal places as instructed |

Format3

Copy link
Contributor

@lilyclements lilyclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bayakarisa this is looking good! I wrote a long review, then decided the easiest way was to illustrate in one place what the amendments to do are, and then you can apply them.

This took a while to look through, and so I hope it should take you a while too in a way. It's important to understand these bits, and so don't worry about being fast. Worry about understanding it. If you have questions, then ask.

You need to pull changes into your branch too before continuing otherwise you'll get errors. 

So, I've made changes and outlined them for the Decimal Places option, you can now take over and do it for the Significant Valuesetc options (Spoiler alert: For Significant Values, I think you just need to add a.SetRCode` argument where I mentioned it, and remove the code in the If statement!

Comment on lines +90 to +99
Private clsGetDataFrameFunction As New RFunction
Private clsColumnsFunction As New RFunction
Private clsPasteFunction As New RFunction
Private clsMutateFunction As New RFunction
Private clsAcrossFunction As New RFunction
Private clsEverythingFunction As New RFunction
Private clsPipeOperator As New ROperator
Private clsTildaOperator As New ROperator
Private clsAssignOperator As New ROperator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I simply moved lines 109-117 up here so that all of our As New RFunction's are together. This can make it easier for the next developer when looking for bits.

Comment on lines -230 to -233
ucrReceiverRank.SetParameter(New RParameter("x", 0))
ucrReceiverRank.SetParameterIsRFunction()


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You set up ucrReceiverRank already (lines 164-169), so I've removed it from here so we don't have duplicated code




ucrPnlNonNegative.AddToLinkedControls(ucrInputPower, {rdoPower}, bNewLinkedHideIfParameterMissing:=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tidying up here by removing additional lines that are empty. I agree having a break of 1 line is nice and neat and makes things readable between different parts, but, can you go through and ensure there is never a break greater than 1 throughout?

ucrNudSignifDigits.AddAdditionalCodeParameterPair(clsSignifColsFunction, New RParameter("digits", 1), iAdditionalPairNo:=1)
ucrInputPower.AddAdditionalCodeParameterPair(clsPowerColsOperator, New RParameter("y", 1), iAdditionalPairNo:=1)

ucrReceiverRank.AddAdditionalCodeParameterPair(clsDescToolsFormatFunction, New RParameter("x", 0), iAdditionalPairNo:=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See next comment, but in that one, I am referring to this line

Comment on lines 787 to +790
ucrReceiverRank.AddAdditionalCodeParameterPair(clsScaleMinColsFunction, New RParameter("x", 0), iAdditionalPairNo:=29)
ucrReceiverRank.AddAdditionalCodeParameterPair(clsBooleanColsOperator, New RParameter("x", 0), iAdditionalPairNo:=30)
ucrReceiverRank.AddAdditionalCodeParameterPair(clsIsNAColsFunction, New RParameter("x", 0), iAdditionalPairNo:=31)
ucrReceiverRank.AddAdditionalCodeParameterPair(clsDescToolsFormatFunction, New RParameter("x", 0), iAdditionalPairNo:=32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You had run this before, but, with one very small issue, which resulted in you writing a huge "If" statement, when it could be done much simpler!

The issue? You put iAdditionalPairNo as 0.

We just want to put it as the next number, and put it with it's "brothers" (the other ucrReceiverRank.AddAdditionalCodeParameterPair's.

We can see on lines 787, we have iAdditionalPairNo := 29, 788 is :=30, 789 is :=31, so, we make this one :=32.
(Note that 1-28 are all in here too, but to avoid having to write all of them out, I have just highlighted the previous few!)

clsFormatFunc.SetPackageName("DescTools")
clsFormatFunc.SetRCommand("Format")
clsFormatFunc.AddParameter("x", strTempVar, bIncludeArgumentName:=False)
clsFormatFunc.AddParameter("digits", ucrNudDecimalPlaces.GetText)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is set up automatically in the SetRCode sub where we have ucrNudDecimalPlaces.SetRCode(...), so we don't need to do it manually here. Neat!

Dim clsFormatFunc As New RFunction
clsFormatFunc.SetPackageName("DescTools")
clsFormatFunc.SetRCommand("Format")
clsFormatFunc.AddParameter("x", strTempVar, bIncludeArgumentName:=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is linked to our Format function in the SetRCode where we now run .AddAdditionalCodeParameterPair with := 32

Comment on lines -959 to -966
Dim clsAddColFunc As New RFunction
clsAddColFunc.SetRCommand("data_book$add_columns_to_data")
clsAddColFunc.AddParameter("data_name", Chr(34) & strDataFrame & Chr(34))
clsAddColFunc.AddParameter("col_name", Chr(34) & strNewVar & Chr(34))
clsAddColFunc.AddParameter("col_data", strNewVar)
clsAddColFunc.AddParameter("before", "FALSE")
clsAddColFunc.AddParameter("adjacent_column", strColumn)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all done automatically in the ucrSave - the ucrSave knows to do all this already, and so we just simply needed to link it to our Format function, which we did when ran ucrSave.AddAdditionalCodeParameterPair with := 16

Comment on lines -967 to -971
Dim clsRmFunc As New RFunction
clsRmFunc.SetRCommand("rm")
clsRmFunc.AddParameter("list", "c(" & Chr(34) & strNewVar & Chr(34) & ", " & Chr(34) & strTempVar & Chr(34) & ")", bIncludeArgumentName:=True)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always done automatically, so this is never needed

Comment on lines -972 to -979
ucrBase.clsRsyntax.ClearCodes()
ucrBase.clsRsyntax.AddToBeforeCodes(clsGetColFunc)
ucrBase.clsRsyntax.AddToBeforeCodes(clsFormatFunc)
ucrBase.clsRsyntax.AddToBeforeCodes(clsAddColFunc)
ucrBase.clsRsyntax.SetBaseRFunction(clsFormatFunc)
ucrBase.clsRsyntax.AddToAfterCodes(clsRemoveLabelsFunction)
ucrBase.clsRsyntax.AddToAfterCodes(clsRmFunc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bits are good, but, it is always the same regardless of which rdo is checked, so we just move this to the end of our If rdoFormat statement

lilyclements and others added 3 commits August 29, 2025 11:34
Forgot to add in one line that I realised when reviewing. That's that we just add

```r
ucrBase.clsRsyntax.SetBaseRFunction(clsDescToolsFormatFunction)
```

at the end of our `If` statemnet for `rdoFormat` :)
@Ag-Derek
Copy link
Collaborator

Ag-Derek commented Oct 7, 2025

@bayakarisa please what is the status on this and is it ready for review

@bayakarisa
Copy link
Collaborator Author

@bayakarisa please what is the status on this and is it ready for review
@Ag-Derek I need you to step in here

I am getting the same script for Percent and decimal since the parameter for both is digits
and fraction too

1.this is the script when i put decimal size 3

size <- data_book$get_columns_from_data(data_name="survey", col_names="size", use_current_filter=FALSE)
size1 <- DescTools::Format(x=size, na.form="Missing", zero.form="0", align="l")
data_book$add_columns_to_data(data_name="survey", col_name="size1", col_data=size1, before=FALSE, adjacent_column="size")

data_book$append_to_variables_metadata(data_name="survey", col_names="size1", property="labels", new_val="")
rm(list=c("size1", "size"))

and here is the script when i put fractions of 3 on size

size <- data_book$get_columns_from_data(data_name="survey", col_names="size", use_current_filter=FALSE)
size1 <- DescTools::Format(digits=3, x=size, fmt=3, na.form="Missing", zero.form="0", align="l")
data_book$add_columns_to_data(data_name="survey", col_name="size1", col_data=size1, before=FALSE, adjacent_column="size")

data_book$append_to_variables_metadata(data_name="survey", col_names="size1", property="labels", new_val="")
rm(list=c("size1", "size"))

@Ag-Derek
Copy link
Collaborator

Ag-Derek commented Oct 8, 2025

Looks like the digits is being called when you actually do the percent parameter, I have sent you a message on whatsapp let me know when you are available within that time

@bayakarisa
Copy link
Collaborator Author

@Ag-Derek @berylwaswa Kindly review this

Comment on lines +1222 to +1256
Private Sub UpdateControlStates()

ucrNudDecimalPlaces.Enabled = False
ucrNudScientific.Enabled = False
ucrNudPercent.Enabled = False
UcrNudFraction.Enabled = False

UcrInputNAOperations.Enabled = False
UcrInputNAvalues.Enabled = False

UcrInputZeroOperations.Enabled = False
UcrInputZeroValues.Enabled = False

UcrInputPvalue.Enabled = False
UcrInputAlignOperations.Enabled = False
UcrInputAlignValues.Enabled = False


If rdoDecimalFormat.Checked Then
ucrNudDecimalPlaces.Enabled = True

ElseIf rdoScientific.Checked Then
ucrNudScientific.Enabled = True

ElseIf rdoPercent.Checked Then
ucrNudPercent.Enabled = True

ElseIf rdoFraction.Checked Then
UcrNudFraction.Enabled = True

ElseIf rdoNA.Checked Then
UcrInputNAOperations.Enabled = True
UcrInputNAvalues.Enabled = True

ElseIf rdoZero.Checked Then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done in the Initialise with the AddToLinkedControls option?

@bayakarisa
Copy link
Collaborator Author

@lilyclements I had already added the sub UpdateControlStates() and done the intitialisation
I have just referenced it cause it wasn't referenced

@lilyclements
Copy link
Contributor

@Ag-Derek and @berylwaswa can you review this?

Copy link
Contributor

@berylwaswa berylwaswa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bayakarisa the radio buttons are all working fine without any errors.

However, I noticed when I first opened the dialog it looked like the image below

instat_2UbBEXDlkY

The decimal places seem to be set by default to 3. But when I click on reset it's changed to zero. And when I go to the next radio button and go back to the decimal radi button it's set to zero. So maybe check that and make sure when someone opens the dialog for the first time it's always set to zero.

@Ag-Derek please check on your end.

@bayakarisa
Copy link
Collaborator Author

@lilyclements , Kindly Check
All minimum developer tests have been completed (OK/TestOK, Reset, UI behaviour, and edge cases). No outstanding issues found. .

Copy link
Contributor

@lilyclements lilyclements left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bayakarisa the code is working great! Just a couple of minor items:

Can you rearrange the rdo's so

  1. They're equally spaced apart?
  2. Can you also move them to the right a bit so they're not covering the group box line on the left hand side? Currently the box is cut off.
  3. They're all aligned to start at the same point
image

You can fix 1 and 3 easily by selecting them all and clicking these:

For 1 -

image

For 3 -

image

Then for two, just selected them all and nudge them to the right a few pixels together.

Can you also check the Test OK enabled again? For example, here OK is enabled. It shouldn't be enabled if the rdo is checked and the associated NUD is empty

image

@bayakarisa
Copy link
Collaborator Author

@lilyclements
I have fixed the testOK for the rdo's such that when rdo is checked and associated NUD is empty the OK is disabled

image

I have rearranged the rdo's. They're equally spaced apart, all aligned to start at the same point.

image

@lilyclements
Copy link
Contributor

@bayakarisa great looks good! @berylwaswa can you test? and @rdstern too?

@lilyclements lilyclements requested a review from rdstern January 22, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Format for numbers into the calculator, and into Transform

5 participants