SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Error with blank Number Control when coding a Custom Dialog

    Posted Thu September 07, 2023 09:47 AM

    Hi,

    I am currently working on a Custom Dialog for running explicit R code.

    I would like to have a Number Control that is not a required field or has a default value. For example, it could be a field where a user can set a seed for a random number generator. The user can either leave it blank, which will mean no seed is set, or enter in a number for the seed. The documentation states that when "the run time value of the number control is empty, then the number control does not generate any command syntax".

    I am at a loss as to how to deal with a Number Control in R when no syntax is sent and not get an error. If the identifier is %%seed%% (and using %%ThisValue%%), I have tried wrapping %%seed%% in a tryCatch block, checking if it exists, assigning it to a variable and checking for errors, but none are working. What I would like to achieve in my R code, is if %%seed%% has a value, set the seed with that number, but if not, do not set a seed. 

    Any help on how to deal with this situation would be much appreciated.

    Many thanks,

    Adam



    ------------------------------
    Adam Lund
    ------------------------------


  • 2.  RE: Error with blank Number Control when coding a Custom Dialog

    Posted Thu September 07, 2023 10:00 AM
    Typically in that situation the seed parameter would be a function argument, and you would define the function signature to assign NULL as the default value, which you can then test for.

    You can see this technique used is a lot of the R-based extension commands available on the Extension Hub.  These are actually commands with full SPSS-style syntax, but that resolves to regular R code.

    Here is an example signature from the STATS FIRTHLOG extension.
    dofirth = function(dep, indep, firth=TRUE, conf=.95, ppl=TRUE, dataset=NULL,
            maxstep=NULL, maxhs=NULL, maxit=NULL, lconv=NULL, gconv=NULL, xconv=NULL,
            plotlist=NULL) {


    --





  • 3.  RE: Error with blank Number Control when coding a Custom Dialog

    Posted Fri September 08, 2023 05:26 AM

    Hi Jon,

    Thank you for your very quick response.

    I have been able to use the technique you described successfully to deal with blank input fields. 

    Thank you for all your help.

    Kind regards,

    Adam



    ------------------------------
    Adam Lund
    ------------------------------