[18627] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Dialog-Function interaction problem

daemon@ATHENA.MIT.EDU (Longhow Lam)
Wed Jul 14 10:17:43 1999

Message-Id: <378C9AA7.6EC04FDE@candiensten.nl>
Date: Wed, 14 Jul 1999 16:11:51 +0200
From: Longhow Lam <lam@candiensten.nl>
Mime-Version: 1.0
To: "Fowler, Mark" <FowlerM@mar.dfo-mpo.gc.ca>
Cc: "'S-news'" <s-news@wubios.wustl.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


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 
	

"Fowler, Mark" wrote:
> 
> 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()
> }
> 
> -----------------------------------------------------------------------
> 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

-- 
Vriendelijke groeten,
Longhow Lam
CANdiensten


PS Keep informed on new releases, updates, courses, etc!

  JOIN OUR ELECTRONIC NEWSLETTER
  look on our home page http://www.candiensten.nl
  _________________________

  CANdiensten                      Longhow Lam
                                   Account Manager

  Nieuwpoortkade 23-25             T +31 20 5608440
  NL-1055 RX Amsterdam             F +31 20 5608448

  info@candiensten.nl              lam@candiensten.nl
  http://www.candiensten.nl

  _________________________

  Your Partner in Mathematics and Statistics!
-----------------------------------------------------------------------
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

home help back first fref pref prev next nref lref last post