[R] User defined function calls

lalitha viswanath lalithaviswanath at yahoo.com
Wed Jan 24 22:03:44 CET 2007


Hi
I have a script processfiles.R that contains, amongst
other functions
1) a database access function called get_clockrates
which retreives from a database, a table containing
columns (clusterid, clockrate) and 45000 rows(one for
each clusterid).
Clusterid is an integer and clockrate is a float.

2) process_clusterid which takes clusterid as an
argument and after doing some data processing,
retrieves the clockrate corresponding to the
clusterid.

I wish to call get_clockrates only once and keep the
dataframe returned by it as a GLOBAL which the
function process_clusterid can use for each clusterid
that it processes.

To ensure that clockrates is global, I retreive it as
clockrate <<- sqlQuery......
Trust that this is correct.

Without the inclusion of get_clockrates function, I
have run this script under R as follows
> source("process_files.R");
> for (index in c(1:45000)) { try(process_file,
silent=TRUE); }

How do I get this code to execute get_clockrates only
once and subsequently call process_file for each of
the 45000 files in turn.

I would greatly appreciate your input regarding my
query.

Thanks
Lalitha


 
____________________________________________________________________________________
Finding fabulous fares is fun.



More information about the R-help mailing list