[R] Inheritance and automatic function call on script exit

Ralf B ralf.bierig at gmail.com
Wed Oct 6 16:59:44 CEST 2010


Hi all,

in order to add certain standard functionality to a large set of
scripts that I maintain, I developed a superscript that I manually
include into every script at the beginning. Here an example of a very
simplified super and subscript.

#
# superscript
#

output <- NULL

writeOutput <- function() {
	processTime <- proc.time()
	outputFilename <- paste("C:/myOutput_", processTime[3], ".csv", sep="")
	write.csv(output, file = outputFilename)
}



#
# subscript
#

source("C:/superscript.R")
output <- data.frame(a=c(1,2,3), b=c(4,5,6))
writeOutput()


I would like to

a) avoid the need to include the super script manually. Does R support
some kind of script inheritance?
b) Is it possible to call writeOutput() automatically when a script is exiting?

Best,
Ralf



More information about the R-help mailing list