[S] Global variables in Splus?

Steve Roberts (sroberts@PICR.man.ac.uk)
Wed, 25 Mar 1998 09:47:53 -0000


I have a function which is used as (for example) the argument to ms. I
want the function to keep some running totals between calls (actually
just to count the number of calls and the length of time spent executing
various bits of the code). So I want to increment some sort of "global"
variable, a concept which S-plus does not have - something like the good
old-fashioned Fortran common block!!! I thought I could do something
with frames but got nowhere.

Something like the following pseudo-script (as a rather trivial

myfunc <- function(things)
.#main function code
.#time variable set to something in here



cat(n,"iterations, ","mean time=",total.time/n)

But of course the n and total.time variables in the function are not the
same as in the main script.

I'm sure it can be done, but how? I'm sure it's trivial once you know!

This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news