From cgenolin at u-paris10.fr  Fri Mar 21 11:47:37 2014
From: cgenolin at u-paris10.fr (Christophe Genolini)
Date: Fri, 21 Mar 2014 11:47:37 +0100
Subject: [Rd] Memcheck: error in a switch using getGraphicsEvent
In-Reply-To: <532B8BA8.7070201@gmail.com>
References: <532B817D.5070606@u-paris10.fr> <532B8BA8.7070201@gmail.com>
Message-ID: <532C18C9.1070405@u-paris10.fr>

Le 21/03/2014 01:45, Duncan Murdoch a ?crit :
> On 2014-03-20, 8:02 PM, Christophe Genolini wrote:
>> Hi the list,
>>
>> One of my package has an (other) error detected by memtest that I do not manage to understand.
>> Here is the message that I get from Memtest
>>
>> --- 8< ----------------
>>   > try(choice(cld1))
>> Error in switch(EXPR = choix, Up = { : EXPR must be a length 1 vector
>> --- 8< ----------------
>>
>> The choice function does call the choiceChangeParam function, which is:
>>
>> --- 8< ----------------
>> choiceChangeParam <- function(paramChoice){
>>
>>       texte <- paste("     ~ Choice : menu    ~\n",sep="")
>>
>>       choix <- getGraphicsEvent(texte,onKeybd=function(key){return(key)})
>>       switch(EXPR=choix,
>>              "Up"    = {
>>                  if(xy[1]>1){
>>                      paramChoice['toDo'] <- "xy"
>>                      xy[2]<-1
>>                      xy[1]<-xy[1]-1
>>                      paramChoice['xy']<-xy
>>                  }else{paramChoice['toDo'] <- ""}
>>              },
>>              "Down"  = {
>>                  if(xy[1]<nrow(paramChoice['critMatrix'])){
>>                      paramChoice['toDo'] <- "xy"
>>                      xy[2]<-1
>>                      xy[1]<-xy[1]+1
>>                      paramChoice['xy']<-xy
>>              "d" = {
>>                  paramChoice['toDo'] <- "changeCriterion"
>>                  paramChoice['critRank'] <- (paramChoice['critRank']%%length(CRITERION_NAMES)) + 1
>>              },
>>              "c" = {
>>                  paramChoice['toDo'] <- "order"
>>              },
>>              default={}
>>
>>              )
>>       return(paramChoice)
>> }
>> --- 8< ----------------
>>
>> choix is a character of lenght 1 since getGraphicsEvent return a character, am I wrong?
>>
>
> It can also return NULL, but to be sure, why not print the value?
>
> Duncan Murdoch
>
>
Thanks for your answer. According to your suggestion, I add the line "cat" between the two other lines:
--- 8< -----------------
     ....
     choix <- getGraphicsEvent(texte,onKeybd=function(key){return(key)})
     cat("Choix : ",choix," class :",class(choix)," length :",length(choix),"\n")
     switch(EXPR=choix,
     ....
--- 8< -----------------

I then make several attempts. In all the cases, the length of choix is 1:

--- 8< ------------------
     ~ Choice : menu ~
Choix :  Down  class : character  length : 1
      ~ Choice : menu ~
Choix :  Up  class : character  length : 1
      ~ Choice : menu ~
Choix :  e  class : character  length : 1
      ~ Choice : menu ~
Choix :  ,  class : character  length : 1
      ~ Choice : menu ~
Choix :     class : character  length : 1
      ~ Choice : menu ~
Choix :  9  class : character  length : 1
      ~ Choice : menu ~
Choix :  ctrl-I  class : character  length : 1
      ~ Choice : menu ~
Choix :  ?  class : character  length : 1
      ~ Choice : menu ~
Choix :  ctrl-J  class : character  length : 1
--- 8< ---------------------

-- 
Christophe Genolini
Ma?tre de conf?rences en bio-statistique
Universit? Paris Ouest Nanterre La D?fense
INSERM UMR 1027



[Rd] Memcheck: error in a switch using getGraphicsEvent
Christophe Genolini