1# Requires xmlOutputBuffer 2 3prompt.xml <- 4function(object, file = NULL, ..., header='<!DOCTYPE Rhelp system "Shelp.dtd">\n\n<Rhelp>',footer="</Rhelp>") 5{ 6 7 local <- list(...) 8 9 name <- substitute(object) 10 11 # Taken from prompt.default 12 is.missing.arg <- function(arg) typeof(arg) == "symbol" && 13 deparse(arg) == "" 14 15 if (is.language(name) && !is.name(name)) 16 name <- eval(name) 17 name <- as.character(name) 18 fn <- get(name) 19 20 xml <- xmlOutputBuffer(nameSpace = "shelp") 21 if(!is.null(header)) 22 xml$add(header) 23 24 xml$addTag("sname",name) 25 xml$addTag("alias",name) 26 xml$addTag("title"," ~~function to do ... ~~ ") 27 28 xml$addTag("description","~~ A concise (1-5 lines) description of what the function does. ~~") 29 30 xml$addTag("usage", close=F) 31 32 33 # Now handle arguments and generate the call. 34 s <- seq(length = n <- length(argls <- formals(fn))) 35 if (n > 0) { 36 arg.names <- names(argls) 37 } 38 xml$addTag("sname", name,sep="") 39 40 for (i in s) { 41 xml$addTag("arg", xml$tagString("argName", arg.names[i]), close=F) 42 43 if(!is.missing.arg(argls[[i]])) { 44 xml$addTag("defaultValue", deparse(argls[[i]]),sep="") 45 } 46 xml$closeTag("arg") 47 if(i < n) 48 xml$addTag("next") 49 } 50 xml$add("</usage>") 51 52 xml$addTag("arguments", close=F) 53 for(i in arg.names) { 54 xml$addTag("argument", xml$tagString("argDescriptionName", i), "\n<argDescription>", 55 "~~Describe ",i," here~~", "</argDescription>") 56 } 57 xml$add("</arguments>") 58 59 60 xml$addTag("details"," ~~ If necessary, more details than the __description__ above ~~") 61 xml$addTag("value", "~Describe the value returned", 62 " If it is a LIST, use", " \\item{comp1 }{Description of `comp1'}", 63 " \\item{comp2 }{Description of `comp2'}", " ...") 64 65 66 xml$addTag("references", ifelse(!is.null(local$references), local$references, "")) 67 68 xml$addTag("author", ifelse(!is.null(local$author), local$author, "")) 69 xml$addTag("note") 70 71 xml$addTag("seeAlso", xml$tagString("a", attrs=list("href"="\"\""))) 72 73 xml$addTag("examples", xml$tagString("example")) 74 75 xml$addTag("keywords", xml$tagString("keyword")) 76 77 if(!is.null(footer)) 78 xml$add(footer) 79 80 val <- xml$value() 81 82 if(!missing(file)) 83 cat(val, file=file) 84 85 val 86} 87 88