askYesNo()

meik michalke meik.michalke at uni-duesseldorf.de
Mon May 7 22:12:57 UTC 2018


hi,

Am Mittwoch, 25. April 2018, 11:10:59 CEST schrieb Thomas Friedrichsmeier:
> On Tue, 24 Apr 2018 12:49:17 +0200
> meik michalke <meik.michalke at uni-duesseldorf.de> wrote:
> > i've seen in the R 3.5.0 changelog that there's a new function called
> > askYesNo() for simple interaction with the user (couldn't test it yet
> > because there's no R 3.5.0 packages for ubuntu 16.04). in RKWard it
> > should trigger a yes/no dialog.
> 
> True. Fortunately there seems to be an option() for setting a custom
> function for this, cleanly. Any volunteer for figuring out, how exactly
> to map this to the existing rk.show.question()?

the least intrusive way of doing this seems to be setting an option:

options("askYesNo"=function(msg, default, prompts, ...){
  response <- rk.show.question(
    message=msg,
    caption=gettext("Question"),
    button.yes=gettext("yes"),
    button.no=gettext("no"),
    button.cancel=gettext("cancel")
  )
  if(is.null(response)){
    stop("Unrecognized response!")
  } else {
    return(response)
  }
})

this works out of the box, but the behaviour is not fully identical.

rk.show.question() currently ignores the default value; askYesNo() returns it 
if no answer was entered (i.e., the user just presses enter when the question 
comes up). to emulate this, rk.show.question() should be able to preselect the 
respective button, where it currently always defaults to "yes".

so, to fully implement askYesNo() without breaking backwards compatibility, we 
could add a new argument to rk.show.question():

  default=TRUE

and when called by askYesNo():

  default=default

but rk.dialog() would have to support this -- does it, yet?

the error if response is NULL emulates what happens when a wrong value is 
entered. askYesNo() raises an error, but if you simply close the 
rk.show.question() dialog it returns NULL.


viele grüße :: m.eik

-- 
  dipl. psych. meik michalke
  institut f"ur experimentelle psychologie
  abt. f"ur diagnostik und differentielle psychologie
  heinrich-heine-universit"at d-40204 d"usseldorf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20180508/5d99594c/attachment.sig>


More information about the rkward-devel mailing list