[R] User defined function calls

From: lalitha viswanath <lalithaviswanath_at_yahoo.com>
Date: Wed 24 Jan 2007 - 21:03:44 GMT

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.


Finding fabulous fares is fun.

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Jan 25 16:17:02 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 25 Jan 2007 - 05:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.