Optional Argument in Jamovi

Everything related to the development of modules in jamovi
Post Reply
julian2
Posts: 20
Joined: Tue Feb 21, 2023 4:29 pm

Optional Argument in Jamovi

Post by julian2 »

For the permutation test in my bmtest module, I would like the user to be able to provide a seed. However, this should be optional. In R, I would do something like seed = NULL as an argument. How do I achieve this in jamovi? I found the Randomizer Module, which also sets a seed. They interpret 0 as no seed (random seed in this case). However, I would prefer this to be represented as empty in the UI and NULL in R, instead of 0.
User avatar
jonathon
Posts: 2847
Joined: Fri Jan 27, 2017 10:04 am

Re: Optional Argument in Jamovi

Post by jonathon »

the arguments in R correspond to the UI in jamovi ... and there's no "standard" way to leave a numeric field "unset" in UI ... so this isn't an area which is "well defined".

one thing you can do is write your own wrapper function, rather than using the one generated by jmvtools. using scatr as an example, jmvtools generates the following function:

https://github.com/jamovi/scatr/blob/ma ... #L133-L206

what you can do is copy the equivalent function, then set:

export: false

in your analysis' .a.yaml file. when you do this, it no longer generates that function in the .h.R file.

then you can paste the no longer generated function into a different file (not into the .h.R!) and customise it to your taste.

jonathon
julian2
Posts: 20
Joined: Tue Feb 21, 2023 4:29 pm

Re: Optional Argument in Jamovi

Post by julian2 »

Thanks for the fast help, great! I decided to go with a two-step approach instead, so that I don’t have to maintain my own wrapper; as shown in the picture below. However, if I update the seed, the results are not recalculated. I would also need the results to recalculate every time the checkbox changes state. Sorry, I forgot how jamovi decides when to recalculate and couldn’t find it in the docs. Current code is here: https://github.com/karchjd/bmtest/tree/jamovi_forum.

Image.
User avatar
jonathon
Posts: 2847
Joined: Fri Jan 27, 2017 10:04 am

Re: Optional Argument in Jamovi

Post by jonathon »

so by default, any change will rerun the whole analysis ... unless you've specified a clearWith:

https://dev.jamovi.org/tuts0203-state.html

jonathon
julian2
Posts: 20
Joined: Tue Feb 21, 2023 4:29 pm

Re: Optional Argument in Jamovi

Post by julian2 »

Thanks for the swift answer and pointing me to the right place in the docs!
Post Reply