R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("pinktoe-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('pinktoe') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "PT" > > ### * PT > > flush(stderr()); flush(stdout()) > > ### Name: PT > ### Title: Traverse rpart object using Tcl Tk GUI > ### Aliases: PT > ### Keywords: iplot tree > > ### ** Examples > > # > # Load rpart library (needed for tree building and execution of PT > # > library("rpart") > library("tcltk") Loading Tcl/Tk interface ... done > data("mpincdf99") > # > # Use supplied function to create a suitable example. > # > z.edm <- makeEDMtree() > # > # Plot tree to look at the basic structure > # > plot(z.edm) > text(z.edm) > # > # Now use PT to graphically traverse tree > # > data("edmbigtext") > ## Not run: PT(z.edm, textfn=edm.text) > # > # Successive widgets appear. You can answer each one using the > # default options if you like (the final classification will be > # "Conservative". > # > # If you have more time then notice that the order of questioning > # and your answers follow the edge structure of the tree. > # > # Notice the large amount of text supplied with each question (variable) > # This is achieved by the edm.text function. > # > > > > cleanEx(); ..nameEx <- "PTTclQ" > > ### * PTTclQ > > flush(stderr()); flush(stdout()) > > ### Name: PTTclQ > ### Title: Traverse tree structure calling appropriate GUI widgets > ### Aliases: PTTclQ > ### Keywords: internal > > ### ** Examples > > # > # Not intended for general user use > # > > > > cleanEx(); ..nameEx <- "PTdialog.leaf" > > ### * PTdialog.leaf > > flush(stderr()); flush(stdout()) > > ### Name: PTdialog.leaf > ### Title: Display text and ok button in a Tcl/Tk widget > ### Aliases: PTdialog.leaf > ### Keywords: internal IO > > ### ** Examples > > # > # Not intended for general use. > # > # Could do: > # > library("tcltk") > ## Not run: PTdialog.leaf("Hello World") > # > # which displays a box with text and ok button! > # > > > > cleanEx(); ..nameEx <- "PTdialog.rpartq" > > ### * PTdialog.rpartq > > flush(stderr()); flush(stdout()) > > ### Name: PTdialog.rpartq > ### Title: Display a dialog box with text, radiobuttons and submit using > ### Tcl/Tk and return submitted answer > ### Aliases: PTdialog.rpartq > ### Keywords: internal IO > > ### ** Examples > > library("tcltk") > ## Not run: > ##D PTdialog.rpartq("Is it possible for a swallow to carry a coconut?", qopts="Yes, certainly", qno="No way", explaintext="A question from Monty Python's Holy Grail") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "PTprocstring" > > ### * PTprocstring > > flush(stderr()); flush(stdout()) > > ### Name: PTprocstring > ### Title: Converts splits information present in an rpart object to an S > ### like format > ### Aliases: PTprocstring > ### Keywords: internal manip > > ### ** Examples > > # > # Process string "Country=abc" for factor variable > # > PTprocstring("Country=abc", "factor") [1] ":abc" > # > # [1] ":abc" > # > # Process string "Weight<=6" for numeric variable > # > PTprocstring("Weight<=6", vtype="numeric") [1] "<=6" > # > # [1] "<=6" > # > > > > cleanEx(); ..nameEx <- "edm.text" > > ### * edm.text > > flush(stderr()); flush(stdout()) > > ### Name: edm.text > ### Title: Example of a textfn function for pinktoe/PT > ### Aliases: edm.text > ### Keywords: datagen > > ### ** Examples > > # > # Which EDMs do we have text for > # > data(edmnumswehave) > data(edmbigtext) > edmnumswehave [1] 29 52 89 110 125 142 175 297 346 391 445 476 493 516 657 770 939 > #[1] 29 52 89 110 125 142 175 297 346 391 445 476 493 516 657 770 939 > # > # > # Ok. Lets look at the text for EDM29. We'll set web=TRUE to get HTML output > # > edm.text("EDM29", web=TRUE) RACE RELATIONS

That this House accepts the fact that the United Kingdom is a multi-racial society; reasserts the right of all individuals to enjoy equal rights irrespective of their race, colour or creed; deplores the fact that racial discrimination continues to blight the lives of many British citizens, and many other ethnic minorities who live in the United Kingdom; and urges the Home Secretary to implement the recommendations by the Commission for Racial Equality and reform the Race Relations Act 1976.
> #RACE RELATIONS > #

> #That this House accepts the fact that the > #United Kingdom is a multi-racial society; reasserts the > #right of all individuals to enjoy equal rights > #irrespective of their race, colour or creed; deplores > #the fact that racial discrimination continues to blight > #the lives of many British citizens, and many > #other ethnic minorities who live in the United > #Kingdom; and urges the Home Secretary to implement > #the recommendations by the Commission for Racial Equality > #and reform the Race Relations Act 1976.
> # > # Do the same thing but return as a character string > # > edm.text("EDM29", web=FALSE) [1] " RACE RELATIONS \n\n That this House accepts the fact that the\n United Kingdom is a multi-racial society; reasserts the\n right of all individuals to enjoy equal rights\n irrespective of their race, colour or creed; deplores\n the fact that racial discrimination continues to blight\n the lives of many British citizens, and many\n other ethnic minorities who live in the United\n Kingdom; and urges the Home Secretary to implement\n the recommendations by the Commission for Racial Equality\n and reform the Race Relations Act 1976.\n" > #[1] " RACE RELATIONS \n\n That this House accepts the fact that the\n United Kingdom is a multi-racial society; reasserts the\n right of all individuals to enjoy equal rights\n irrespective of their race, colour or creed; deplores\n the fact that racial discrimination continues to blight\n the lives of many British citizens, and many\n other ethnic minorities who live in the United\n Kingdom; and urges the Home Secretary to implement\n the recommendations by the Commission for Racial Equality\n and reform the Race Relations Act 1976.\n" > > > > cleanEx(); ..nameEx <- "edmbigtext" > > ### * edmbigtext > > flush(stderr()); flush(stdout()) > > ### Name: edmbigtext > ### Title: Character vector containing all text necessary for the edm.text > ### function > ### Aliases: edmbigtext > ### Keywords: datasets > > ### ** Examples > > data(edmbigtext) > # > # Using edm.text > # > edm.text("EDM939") USE OF PARLIAMENTARY TIME

That this House welcomes the recommendation by the Modernisation Committee to timetable business so that the last stand alone votes are taken at 10.00 p.m. thereby ending the practice of making legislation in the early hours of the morning; notes that backbenchers and opposition parties are to be given control over how the time for debating a bill is used; and believes that this will make for better scrutiny, better legislation and better government.
> #USE OF PARLIAMENTARY TIME > #

> #That this House welcomes the recommendation by the > #Modernisation Committee to timetable business so that the > #last stand alone votes are taken at 10.00 > #p.m. thereby ending the practice of making legislation > #in the early hours of the morning; notes > #that backbenchers and opposition parties are to be > #given control over how the time for debating > #a bill is used; and believes that this > #will make for better scrutiny, better legislation and > #better government.
> > > > cleanEx(); ..nameEx <- "edmnum99" > > ### * edmnum99 > > flush(stderr()); flush(stdout()) > > ### Name: edmnum99 > ### Title: Complete list of EDM numbers for 1999 > ### Aliases: edmnum99 > ### Keywords: datasets > > ### ** Examples > > data(edmnum99) > # > # Let's just have a look at a few > # > edmnum99[11:20] [1] "11" "12" "12A1" "13" "14" "15" "16" "17" "18" "19" > # [1] "11" "12" "12A1" "13" "14" "15" "16" "17" "18" "19" > # > # Note that EDM12 has an amendment also, EDM12A1 > # > > > > cleanEx(); ..nameEx <- "edmnumswehave" > > ### * edmnumswehave > > flush(stderr()); flush(stdout()) > > ### Name: edmnumswehave > ### Title: List of the EDM numbers that can be accessed by the edm.text > ### function > ### Aliases: edmnumswehave > ### Keywords: datasets > > ### ** Examples > > data(edmnumswehave) > # > # Not really worth an example > # > > > > cleanEx(); ..nameEx <- "genedmhtml" > > ### * genedmhtml > > flush(stderr()); flush(stdout()) > > ### Name: genedmhtml > ### Title: Generate HTML and perl files to enable tree traversal > ### Aliases: genedmhtml > ### Keywords: datagen > > ### ** Examples > > # > #Not intended for general user use > # > > > > cleanEx(); ..nameEx <- "genericcommonhtml" > > ### * genericcommonhtml > > flush(stderr()); flush(stdout()) > > ### Name: genericcommonhtml > ### Title: An example of some common html to go at the end of HTML pages > ### for Pinktoe > ### Aliases: genericcommonhtml > ### Keywords: misc > > ### ** Examples > > # > # The "" makes the output go to standard output (ie on the console) > # > genericcommonhtml(file="", append=TRUE) Return to Guy Nason's home page > #Return to Guy Nason's home page > # > # Of course this is an example function which you can modify to say whatever you like! > > > > cleanEx(); ..nameEx <- "kyphosis.text" > > ### * kyphosis.text > > flush(stderr()); flush(stdout()) > > ### Name: kyphosis.text > ### Title: Print explanatory text concerning kyphosis variables. > ### Aliases: kyphosis.text > ### Keywords: datagen > > ### ** Examples > > # > # Here is a simple example > # > kyphosis.text("Start")
Variable: Start : The beginning of the range of vertabrae involved
> #
> #Variable: Start : The beginning of the range of vertabrae involved
> > > > cleanEx(); ..nameEx <- "kyphosisprint" > > ### * kyphosisprint > > flush(stderr()); flush(stdout()) > > ### Name: kyphosisprint > ### Title: Example stateprintfn for the pinktoe function arising from the > ### kyphosis example > ### Aliases: kyphosisprint > ### Keywords: datagen > > ### ** Examples > > # > # A quick example. The file here is specified as "" to cat to standard output > # > kyphosisprint("present") &present; > # &present; > > > > cleanEx(); ..nameEx <- "kyphosistittext" > > ### * kyphosistittext > > flush(stderr()); flush(stdout()) > > ### Name: kyphosistittext > ### Title: An example of a tittext function for the pinktoe function with > ### the kyphosis example. > ### Aliases: kyphosistittext > ### Keywords: datagen > > ### ** Examples > > # > # Try it out with the variable name "Start" > # > kyphosistittext("Start") [1] "Variable: Start" > #[1] "Variable: Start" > > > > cleanEx(); ..nameEx <- "makeEDMtree" > > ### * makeEDMtree > > flush(stderr()); flush(stdout()) > > ### Name: makeEDMtree > ### Title: Construct a tree for one of the examples showing how pinktoe > ### works > ### Aliases: makeEDMtree > ### Keywords: datagen > > ### ** Examples > > # > # Build the tree after loading rpart library > # > library("rpart") > data("mpincdf99") > mpincdf99tree <- makeEDMtree() > > > > cleanEx(); ..nameEx <- "mpall3" > > ### * mpall3 > > flush(stderr()); flush(stdout()) > > ### Name: mpall3 > ### Title: Master database of MP information concerned with EDM example > ### Aliases: mpall3 > ### Keywords: datasets > > ### ** Examples > > data(mpall3) > # > # The name of MP number 3 > # > mpall3$mpn[3] [1] Adams, Irene 670 Levels: Abbott, Miss Diane Adams, Gerry# Adams, Irene ... Young, Rt Hon Sir George Bt > # > # This record corresponds to Irene Adams > # > #[1] Adams, Irene > #670 Levels: Abbott, Miss Diane Adams, Gerry# Adams, Irene ... Young, Rt Hon Sir George Bt > mpall3$mpcon[3] [1] Paisley North 660 Levels: Aberavon Aberdeen Central Aberdeen North ... York, City of > # > # Her constituency is Paisley North > # > #[1] Paisley North > #660 Levels: Aberavon Aberdeen Central Aberdeen North ... York, City of > mpall3$mpparty[3] [1] Lab 16 Levels: Con DCWM DU Ind LDem Lab Lib PC SDLP SF SNP SPK Scot Lab UKU ... WW > # > # She is a Labour MP > # > #[1] Lab > #16 Levels: Con DCWM DU Ind LDem Lab Lib PC SDLP SF SNP SPK Scot Lab UKU ... WW > mpall3$mpregion[3] [1] NorthWest 9 Levels: London Midland NI NorthEast NorthWest Scotland ... Wales > # > # Her constituency is in the North West of England > # > #[1] NorthWest > #9 Levels: London Midland NI NorthEast NorthWest Scotland ... Wales > # > # She is Female > # > mpall3$mpgender[3] [1] F Levels: F M > #[1] F > #Levels: F M > mpall3$mpage[3] [1] 53 > # > # She was 53 at the census date > # > #[1] 53 > mpall3$mpagecod[3] [1] 5 > # > # She was in her fifties > # > #[1] 5 > > > > cleanEx(); ..nameEx <- "mpinc99" > > ### * mpinc99 > > flush(stderr()); flush(stdout()) > > ### Name: mpinc99 > ### Title: EDM signing database for 1999 > ### Aliases: mpinc99 > ### Keywords: datasets > > ### ** Examples > > data(mpinc99) > ## maybe str(mpinc99) ; plot(mpinc99) ... > # > # Did Irene Adams sign EDM3 ? > # > mpinc99[2, 3] [1] 0 > # [1] 0 > # > # No, she didn't! > > > > cleanEx(); ..nameEx <- "mpincdf99" > > ### * mpincdf99 > > flush(stderr()); flush(stdout()) > > ### Name: mpincdf99 > ### Title: EDM signing database for 1999 and party affiliation for MPs > ### Aliases: mpincdf99 > ### Keywords: datasets > > ### ** Examples > > data(mpincdf99) > ## maybe str(mpincdf99) ; plot(mpincdf99) ... > # > # Let's look at the first 5 MPs and the first 4 EDMs. > # > mpincdf99[1:5,1:5] party EDM1 EDM2 EDM3 EDM4 Abbott/Diane Lab SIGNED NOT SIGNED NOT Adams/Irene Lab NOT NOT NOT SIGNED Ainger/Nick Lab NOT NOT NOT NOT Ainsworth/Peter Con NOT NOT NOT NOT Alexander/Douglas Lab NOT NOT NOT NOT > # party EDM1 EDM2 EDM3 EDM4 > #Abbott/Diane Lab SIGNED NOT SIGNED NOT > #Adams/Irene Lab NOT NOT NOT SIGNED > #Ainger/Nick Lab NOT NOT NOT NOT > #Ainsworth/Peter Con NOT NOT NOT NOT > #Alexander/Douglas Lab NOT NOT NOT NOT > # > # So, Diane signed EDM1 and EDM3 and not EDM2 and EDM4 etc.... > > > > cleanEx(); ..nameEx <- "partycommonhtml" > > ### * partycommonhtml > > flush(stderr()); flush(stdout()) > > ### Name: partycommonhtml > ### Title: Function to produce HTML at the end of all EDM HTML pages > ### Aliases: partycommonhtml > ### Keywords: datagen > > ### ** Examples > > # > # A simple example where filename="" to show result on the screen > # > partycommonhtml("", TRUE) Return to Who to Vote For page > # Return to Who to Vote For page > > > > cleanEx(); ..nameEx <- "partyprint" > > ### * partyprint > > flush(stderr()); flush(stdout()) > > ### Name: partyprint > ### Title: Function suitable for use as the stateprintfn argument for > ### pinktoe for the EDM example > ### Aliases: partyprint > ### Keywords: datagen > > ### ** Examples > > partyprint("Lab", file="", append=TRUE) &labour; > # &labour; > # > # > # So the perl function labour gets called. > > > > > cleanEx(); ..nameEx <- "partytittext" > > ### * partytittext > > flush(stderr()); flush(stdout()) > > ### Name: partytittext > ### Title: Returns the variable label > ### Aliases: partytittext > ### Keywords: datagen > > ### ** Examples > > # > # Try it with the "EDM29" variable name > # > partytittext("EDM29") [1] "EDM29" > # [1] "EDM29" > > > > cleanEx(); ..nameEx <- "pinktoe" > > ### * pinktoe > > flush(stderr()); flush(stdout()) > > ### Name: pinktoe > ### Title: Pinktoe: convert S trees to web files for interactive traversal. > ### Aliases: pinktoe > ### Keywords: iplot tree > > ### ** Examples > > # > # Attach rpart library > # > library("rpart") > data("mpincdf99") > # > # Create a tree (rpart object) > # > z.edm <- makeEDMtree() > # > # Plot the tree to see its basic structure. > # > plot(z.edm) > text(z.edm) > # > # Now use pinktoe to generate a set of htm and pl files that can be used > # by a CGI-enabled web server to traverse the tree. > # > data("edmbigtext") > # > # Next code requires "sfsmisc" library. This is not installed by default > # in R distributions so you'll have to get it yourself. We make sure > # that the next code doesn't run because R CMD check can't install packages (I think) > # > ## Not run: > ##D pinktoe(z.edm, edm.text, partytittext, treeid="", localdir="./", > ##D cgibindir="/~magpn/cgi-bin/TEST/", > ##D htmldir="/home/magpn/public_html/TEST/", stateprintfn=partyprint, > ##D requirelib="../party.lib", > ##D commonhtml=partycommonhtml) > ## End(Not run) > # Frame row number is 1 > # Node number is 1 > # Frame row number is 2 > # Node number is 2 > # Frame row number is 3 > # Node number is 4 > # Frame row number is 4 > # Node number is 8 > # Frame row number is 6 > # Node number is 17 > # Frame row number is 7 > # Node number is 34 > # Frame row number is 8 > # Node number is 68 > # Frame row number is 9 > # Node number is 136 > # Frame row number is 17 > # Node number is 3 > # > # If you look in the current directory you'll find a load of perl and > # HTML files created. > # > > > > cleanEx(); ..nameEx <- "pv99tompall" > > ### * pv99tompall > > flush(stderr()); flush(stdout()) > > ### Name: pv99tompall > ### Title: Permutation vector from MP lists in 99 into the mpall3 database > ### Aliases: pv99tompall > ### Keywords: datasets > > ### ** Examples > > data(pv99tompall) > data(mpall3) > data(mpinc99) > # > # In the mpincdf object (which records EDM signings) Irene Adams is MP number 2. Let's check this > # > dimnames(mpinc99)[[1]][1:5] [1] "Abbott/Diane" "Adams/Irene" "Ainger/Nick" [4] "Ainsworth/Peter" "Alexander/Douglas" > #[1] "Abbott/Diane" "Adams/Irene" "Ainger/Nick" > #[4] "Ainsworth/Peter" "Alexander/Douglas" > # > # What number is she in the mpall3 database? > # > pv99tompall[2] [1] 3 > # [1] 3 > # > # She is the third MP in this structure. (You see possibly number 1 or 2 in mpall3 did not sign anything > # in 1999. > # > # Let's check > # > mpall3$mpn[3] [1] Adams, Irene 670 Levels: Abbott, Miss Diane Adams, Gerry# Adams, Irene ... Young, Rt Hon Sir George Bt > #[1] Adams, Irene > #670 Levels: Abbott, Miss Diane Adams, Gerry# Adams, Irene ... Young, Rt Hon Sir George Bt > # > # Yep, that's her! > > > > cleanEx(); ..nameEx <- "splits.rpart" > > ### * splits.rpart > > flush(stderr()); flush(stdout()) > > ### Name: splits.rpart > ### Title: Create splits data frame that seems to be missing from R rpart > ### code > ### Aliases: splits.rpart > ### Keywords: iplot tree > > ### ** Examples > > library("rpart") > data(kyphosis) > z.kyphosis <- rpart(kyphosis) > # > # Now check that there is no splits.cutleft or splits.cutright component > # of the frame component as there is in S > # > dimnames(z.kyphosis$frame)[[2]] [1] "var" "n" "wt" "dev" "yval" [6] "complexity" "ncompete" "nsurrogate" "yval2" > # > #[1] "var" "n" "wt" "dev" "yval" > #[6] "complexity" "ncompete" "nsurrogate" "yval2" > # > # Nope! So let's use our function to make them > # > splits.rpart(z.kyphosis) splits.cutleft splits.cutright 1 >=8.5 < 8.5 2 >=14.5 < 14.5 3 4 < 55 >=55 5 6 >=111 < 111 7 8 9 > # > # splits.cutleft splits.cutright > #1 >=8.5 < 8.5 > #2 >=14.5 < 14.5 > #3 > #4 < 55 >=55 > #5 > #6 >=111 < 111 > #7 > #8 > #9 > # > # The resultant object could be installed into the frame component > # (as happens in the early code lines of PT and pinktoe) by > # > # z.kyphosis$frame <- cbind(z.kyphosis$frame, splits.rpart(z.kyphosis)) > > > > cleanEx(); ..nameEx <- "writehtml" > > ### * writehtml > > flush(stderr()); flush(stdout()) > > ### Name: writehtml > ### Title: Write the HTML file for an EDM decision and return the names of > ### the called perl files so that they can be constructed. > ### Aliases: writehtml > ### Keywords: internal > > ### ** Examples > > # > #Not intended for general user use > # > > > > cleanEx(); ..nameEx <- "writeperl" > > ### * writeperl > > flush(stderr()); flush(stdout()) > > ### Name: writeperl > ### Title: Writes the perl file(s) for pinktoe > ### Aliases: writeperl > ### Keywords: internal > > ### ** Examples > > # > #Not intended for general user use > # > > > > cleanEx(); ..nameEx <- "writeperloption" > > ### * writeperloption > > flush(stderr()); flush(stdout()) > > ### Name: writeperloption > ### Title: Generate part of the perl file. > ### Aliases: writeperloption > ### Keywords: internal > > ### ** Examples > > # > #Not intended for general user use > # > > > > ### *