s-news
[Top] [All Lists]

[S] Summary of responses to 'Dialog-Function interaction problem'

To: "'S-news'" <s-news@wubios.wustl.edu>
Subject: [S] Summary of responses to 'Dialog-Function interaction problem'
From: "Fowler, Mark" <FowlerM@mar.dfo-mpo.gc.ca>
Date: Wed, 14 Jul 1999 13:20:00 -0300
Sender: owner-s-news@wubios.wustl.edu
Sincere thank you to Longhow Lam and Brad Biggerstaff. Both problems solved
(one by each). And within two hours of posing the questions.

ORIGINAL QUERY TO THE LIST

I'm new to the joys of writing GUIs. Trying to pass arguments from a dialog
to a function, I've encountered one critical obstacle involving character
options in a Multi-select Box, and one bothersome solution to another
obstacle concerned with passing arguments to a function.  

The critical problem arises from the need to provide a list of
three-character geographic region codes with which users are familiar (and
all start with a number and end with a letter or blank). Almost any
combination of these areas might be desired. Whether I pass the selection as
a list or a character, all  blanks are eliminated. And if passed as a list
the argument aborts the function due to parse error. It can't handle a list
like c(5, 4V,4X,4WK):

Message: Error in parse(text = txt): Syntax error: name ("V") used illegally
at this point:
CRDataSel(s = "hakewhite", g = "longline", e = "numberofhooks" ...

And if passed as a character this would translate to "5,4V,4X,4WK". The
latter is readable, but problematic. And using IsList=T and UseQuotes=T
simultaneously doesn't put quotes around the separate elements of the list.
Ideally I would want the selection passed as a list in the original
(character) format used in guiCreate, like c("5  ","4V ","4X ","4WK"), but
don't know how (or if) this can be accomplished. Alternatively I need a way
to convert the single character argument to a list of characters.

For obstacle #2, the first of several arguments being passed by the dialog
to the function is getting interpreted as an object to which the remaining
arguments are assigned. The remaining arguments, however, are still passed
to the function. So for now I've just created a "junk" property as the first
element in the ProprtyList of FunctioInfo, which serves to pass all the
'remaining' arguments to my function. This seems silly, and I assume a
better approach exists.

Anyone know a resolution to either of these problems? In case it matters,
I'm running S-Plus 2000 on a Pentium II with Windows 95. I double-click
CRDataSel to invoke the dialog.

The function and dialog creation:

CRDataSel_function(s,g,e,r,a,y1,y2,m1,m2,tc1,tc2,dz1,dz2,pmsc,yc1,yc2,cfvy,c
fvcy){
spec_switch(s,argentineatlantic=351,capelin=360,codatlantic=100,cusk=173,dog
fishspiny=362,
        
flounderwinter=143,flounderwitch=142,flounderyellowtail=141,grenadierroundno
se=179,
        
haddock=110,hakesilver=172,hakewhite=171,halibutatlantic=130,herring=200,mon
kfish=177,
        
plaiceamerican=140,pollock=170,redfish=120,sharkblue=372,sharkporbeagle=369,
        skatewinter=356,turbot=144,wolffish=174)
gear_switch(g,sternottertrawl=12,longline=51,gillnet=41,Danishseine=21,purse
seine=31,
        weir=63)
effcode_switch(e,numberofhooks=1,hoursfished=2,linestubsfished=3,daysfished=
4,
        sizeofnet=5)
reccode_switch(r,set=1,subtrip=2,trip=3)
a1_c("3  ","4  ","5  ","3P ","3O ","4R ",
        "4S ","4T ","4V ","4W ","4X ","5Y ","5Z ","4VN","4VA","4VB",
        "4WD","4WE","4WF","4WG","4WH","4WJ","4WK","4WL","4WM",
        "4XM","4XN","4XO","4XP","4XQ","4XR","4XS")
a2_c("3  ","3P ","3O ")
a3_c("4  ","4R ",
        "4S ","4T ","4V ","4W ","4X ","4VN","4VA","4VB",
        "4WD","4WE","4WF","4WG","4WH","4WJ","4WK","4WL","4WM",
        "4XM","4XN","4XO","4XP","4XQ","4XR","4XS")
a4_c("5  ","5Y ","5Z ")
a5_c("4V ","4VN","4VA","4VB")
a6_c("4W ","4WD","4WE","4WF","4WG","4WH","4WJ","4WK","4WL","4WM")
a7_c("4X ","4XM","4XN","4XO","4XP","4XQ","4XR","4XS")
if(is.element("All", a))a_union(a,a1)
if(is.element("3  ", a))a_union(a,a2)
if(is.element("4  ", a))a_union(a,a3)
if(is.element("5  ", a))a_union(a,a4)
if(is.element("4V ", a))a_union(a,a5)
if(is.element("4W ", a))a_union(a,a6)
if(is.element("4X ", a))a_union(a,a7)
areas_a
subce1_cateff[cateff$SPEC==spec & cateff$GEAR==gear &
cateff$EFFCODE==effcode & cateff$RECCODE==reccode
 & cateff$PERMSC>=as.numeric(pmsc),]
nafo_match(as.character(subce1$AREA), as.character(areas),nomatch=0)
subce2_subce1[nafo>0,]
subce3_subce2[subce2$YEAR>=as.numeric(yc1) & subce2$YEAR<=as.numeric(yc2),]
hist.tab_table(subce3$CFV,subce3$YEAR)
hmat1_hist.tab/hist.tab
totyears_apply(hmat1,1,sum,na.rm=T)
y_as.numeric(as.character(sort(unique(subce3$YEAR))))
hmat2_ t(y/t(hmat1))
cy_data.frame(t(apply(hmat2,1,diff)))
newcy_cy
for(nr in 1:dim(cy)[1]){
for (nc in 1:dim(cy)[2]){
  if(is.na(cy[nr,nc]) || cy[nr,nc]>1)newcy[nr,nc]_NA
}
}
cy_newcy
conyears_1+apply(cy,1,sum,na.rm=T)
CFV_row.names(cy)
newdf_data.frame(cy,CFV,totyears,conyears)
histcfv_newdf$CFV[newdf$totyears>=as.numeric(cfvy) &
newdf$conyears>=as.numeric(cfvcy)]
cfvrec_match(as.character(subce3$CFV), as.character(histcfv),nomatch=0)
subce4_subce3[cfvrec>0,]
subce5<<-subce4[subce4$YEAR>=as.numeric(y1) & subce4$YEAR<=as.numeric(y2)
 & subce4$MONTH>=as.numeric(m1) & subce4$MONTH<=as.numeric(m2)
 & subce4$TONCL>=as.numeric(tc1) & subce4$TONCL<=as.numeric(tc2)
 & subce4$DEPZONE>=as.numeric(dz1) & subce4$DEPZONE<=as.numeric(dz2),]
list("Number of cases" = length(subce5$YEAR),"Catch in
tons"=sum(subce5$MTONS),
"Cases per year"=tapply(subce5$MTONS,subce5$YEAR,length),
"Catch per year"=tapply(subce5$MTONS,subce5$YEAR,sum),
"Number of vessels"=length(unique(subce5$CFV)))
}


stanbox1_function(){
guiCreate("Property", Name = "SpecList", DialogControl = "List Box",   
          DialogPrompt = "Species", DefaultValue = "hakewhite",
        OptionList =
c("argentineatlantic","capelin","codatlantic","cusk","dogfishspiny",
        "flounderwinter","flounderwitch","flounderyellowtail",
        "grenadierroundnose","haddock","hakesilver","hakewhite",
        "halibutatlantic","herring","monkfish","plaiceamerican","pollock",
        "redfish","sharkblue","sharkporbeagle","skatewinter",
        "turbot","wolffish"),UseQuotes=T)
guiCreate("Property", Name = "GearList", DialogControl = "List Box",   
          DialogPrompt = "Gear", DefaultValue = "longline",
        OptionList =
c("sternottertrawl","longline","gillnet","Danishseine","purseseine",
        "weir"),UseQuotes=T)
guiCreate("Property", Name = "EffList", DialogControl = "List Box",   
          DialogPrompt = "Effort Measure", DefaultValue = "numberofhooks",
        OptionList =
c("numberofhooks","hoursfished","linestubsfished","daysfished",
        "sizeofnet"),UseQuotes=T)
guiCreate("Property", Name = "RecList", DialogControl = "List Box",   
          DialogPrompt = "Data Aggregation", DefaultValue = "set",
        OptionList = c("set","subtrip","trip"),UseQuotes=T)
guiCreate("Property", Name = "AreaList", DialogControl = "Multi-select List
Box",   
          DialogPrompt = "NAFO Areas", DefaultValue = "All",
        OptionList = c("All","3  ","4  ","5  ","3P ","3O ","4R ",
        "4S ","4T ","4V ","4W ","4X ","5Y ","5Z ","4VN","4VA","4VB",
        "4WD","4WE","4WF","4WG","4WH","4WJ","4WK","4WL","4WM",
        "4XM","4XN","4XO","4XP","4XQ","4XR","4XS"),UseQuotes=T,IsList=T)
guiCreate("Property", Name = "YearSel1", DialogControl = "Integer Range",   
          DialogPrompt = "Start Year", DefaultValue = "1991",
        Range = "1991:1999",UseQuotes=T)
guiCreate("Property", Name = "YearSel2", DialogControl = "Integer Range",   
          DialogPrompt = "End Year", DefaultValue = "1999",
        Range = "1991:1999",UseQuotes=T)
guiCreate("Property", Name = "MonthSel1", DialogControl = "Integer Range",

          DialogPrompt = "Start Month", DefaultValue = "1",
        Range = "1:12",UseQuotes=T)
guiCreate("Property", Name = "MonthSel2", DialogControl = "Integer Range",

          DialogPrompt = "End Month", DefaultValue = "12",
        Range = "1:12",UseQuotes=T)
guiCreate("Property", Name = "TCSel1", DialogControl = "Integer Range",   
          DialogPrompt = "Smallest Tonnage Class", DefaultValue = "1",
        Range = "1:7",UseQuotes=T)
guiCreate("Property", Name = "TCSel2", DialogControl = "Integer Range",   
          DialogPrompt = "Largest Tonnage Class", DefaultValue = "7",
        Range = "1:7",UseQuotes=T)
guiCreate("Property", Name = "DZSel1", DialogControl = "Integer Range",   
          DialogPrompt = "Shoalest Depth Zone", DefaultValue = "1",
        Range = "1:9",UseQuotes=T)
guiCreate("Property", Name = "DZSel2", DialogControl = "Integer Range",   
          DialogPrompt = "Greatest Depth Zone", DefaultValue = "9",
        Range = "1:9",UseQuotes=T)
guiCreate("Property", Name = "PerMSC", DialogControl = "Integer Range",   
          DialogPrompt = "Min % main species", DefaultValue = "1",
        Range = "1:100",UseQuotes=T)
guiCreate("Property", Name = "YearCFV1", DialogControl = "Integer Range",   
          DialogPrompt = "CFV History Start Year", DefaultValue = "1981",
        Range = "1981:1999",UseQuotes=T)
guiCreate("Property", Name = "YearCFV2", DialogControl = "Integer Range",   
          DialogPrompt = "CFV History End Year", DefaultValue = "1999",
        Range = "1991:1999",UseQuotes=T)
guiCreate("Property", Name = "CFVYears", DialogControl = "Integer Range",   
          DialogPrompt = "CFV History Min No of Years", DefaultValue = "10",
        Range = "1:20",UseQuotes=T)
guiCreate("Property", Name = "CFVConYears", DialogControl = "Integer Range",

          DialogPrompt = "CFV History Min No of Consecutive Years",
DefaultValue = "5",
        Range = "1:20",UseQuotes=T)
guiCreate("Property", Name = "junk")
guiCreate("FunctionInfo", Name="CRDataSel",Function= "CRDataSel",
         DialogHeader = "Catch Rate Analysis - Data Selection",
          PropertyList =
c("junk","SpecList","GearList","EffList","RecList","AreaList","YearSel1","Ye
arSel2","MonthSel1","MonthSel2","TCSel1","TCSel2","DZSel1","DZSel2","PerMSC"
,"YearCFV1","YearCFV2","CFVYears","CFVConYears"))
invisible() 
}



SOLUTION TO PROBLEM #1

Dear Mark,

For obstacle 1 use the following trick

tmp.func <- function(.....,variables,....){
...
if(!is.null(variables) && (length(variables) > 1 || variables != ""))
        variables <- sapply(unpaste(variables, sep = ","), strip.blanks)
...
}

where variables is the input "5,4V,4X,4WK" from the GUI.

This trick is used by the function menuDescribe, the function that is
ran if you calculate summary statistics from the GUI.

Longhow 



SOLUTION TO PROBLEM #2

I only had time to skim, but on your problem 2, the argument #0 is what is
returned by the function, so that what's returned can be saved; that's by
design so what's returned can be used.  All others, #1, #2, etc. are for the
function proper.  You can create a CRDataSelSaveAs property (basically what
you did with "junk") and then specify these arguments in FunctionInfo using
ArgumentList (rather than PropertyList) explicitly, as 

        guiCreate("Property", Name = "CRDataSelSaveAs", DialogPrompt = "Save
As", DialogControl = 
                "String", DefaultValue = "last.crdatasel")
        #
      # then include this property on, say, a model or options page in the
PropertyList
        # and now
        #
        guiCreate("FunctionInfo", Name="CRDataSel",Function= "CRDataSel",
                 DialogHeader = "Catch Rate Analysis - Data Selection",
                  ArgumentList = 
        
#0=CRDataSelSaveAs,#1="SpecList",#2="GearList",#3="EffList",#4="RecList,...


Again, this is basically what you did, but the reasoning behind it is to
have the object the function returns available.

When I have a bit more time, I'll try to look at your other problem, but
hopefully you'll have an answer by then.

Cheers,
brad

Brad Biggerstaff, Ph.D.
Centers for Disease Control and Prevention
National Center for Infectious Diseases
Division of Vector-Borne Infectious Diseases
P.O. Box 2087
Fort Collins, CO  80522-2087   U.S.A.
(970) 221-6473              bkb5@cdc.gov

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>