[R] Advice on good programming practice, lexical scope

Sixten Borg sb at ihe.se
Wed Sep 1 10:21:57 CEST 2004

In "An Introduction to R" (See R help menu), there is an example of a function 'open.account' that makes use of the lexical scope in R.

I have a set of functions that can be used to output R tables and graphics into a single report document. (I am aware that several tools can do this already).

While reorganizing my code, I realize that I can collect my functions in a list, in the style of 'open.account' above. This will result in a list containing data and operations on those data. The data is for example the file name of the report. This also results in a rather large object instead of a set of rather small functions and a list of data.

Writing a package of these functions (or this object containing functions), would require documentation of each function. The style that I see in the R help is that the functions are not enclosed like this in a list. 

I like the idea of having the functions collected in a single list, but I think the documentation might be messy. 
Any ideas, opinions, anyone?

Thanks in advance,


myreport <- report(filename="report.rtf")
my.report$add.table(my.data.frame, "Table of ...")
my.report$add.picture("Plot of ...")


r <- report(filename="report.rtf")
r <- add.table(r, my.data.frame, "Table of...")
r <- add.picture(r, "Plot of...")

More information about the R-help mailing list