swh:1:snp:a4c99a50dc49f82b591f268001b320f8c3ca0041
Tip revision: dc000f2a5f006d137f66716b086025d618bf8306 authored by John M Chambers on 14 July 2008, 00:00:00 UTC
version 1.0-5
version 1.0-5
Tip revision: dc000f2
runExample.R
runExample <- function(what, where = "SoDA", run = TRUE, ..., echo = TRUE, prompt.echo, wd ) {
file = exampleFiles(what, where, TRUE, TRUE) # one file, with path
fileB = sub("^.*/","",file)
if(length(grep("[.][RS]$", file)) >0 ) {
if(run) {
if(missing(wd))
wd <- system.file(package=where)
if(!nzchar(wd)) {
oldwd <- getwd()
setwd(wd)
on.exit(setwd(oldwd))
}
message(gettextf("Running example file \"%s\"", file),
domain = NA)
if(missing(prompt.echo))
prompt.echo <- paste(">",abbreviate(substr(fileB, 1, nchar(file)-2),4)," ", sep="")
source(file, ..., echo = echo, prompt.echo = prompt.echo)
}
else {
value <- parse( file)
if(length(value) == 1) #e.g., and often, a function definition
value <- value[[1]]
value
}
}
else { # should offer the user some choices?
file
}
}
.guessFile <- function(what, files) {
pattern <- paste(what, ".R", sep="")
which <- match(pattern, files)
if(!is.na(which))
return(files[which])
pattern <- paste("^",what, sep="")
which <- grep(pattern, files)
if(length(which) > 0)
return(files[which])
## should try for other languages, in case regexp failed?
character()
}