1. holdem. 2. C++. 3. Python and MySQL references. 4. Calling R from C. 1. holdm. 2. C++. In myfile.cpp, #include #include #include #include using namespace std; extern "C" { void hello (int *n) { int i,j; double a2; for(i = 1; i < *n+1; i++) { a2 = sqrt(i); cout << "The square root of " << i << " = " << a2 << ".\n"; } cout << "\n How many cubes do you want? "; cin >> j; for(i = 1; i < j+1; i++){ a2 = pow(i,3); cout << i << " to the 3rd power = " << a2 << ".\n"; } } } In R: system("R CMD SHLIB myfile.cpp") dyn.load("myfile.so") .C("hello",as.integer(7)) 3. Python and MySQL references. For Python, a nice introduction is http://www.rexx.com/~dkuhlman/python_101/python_101.html . There are many nearly equivalent online references. For MySQL, a good reference is King, T., Reese, G., Yarger, R., and Williams, H.E. (2002). Managing and Using MySQL: Open Source SQL Databases for Managing Information and Web Sites, 2nd ed. O'Reilly and Associates, Inc., Sebastopol, CA. Or Sams Teach Yourself SQL in 10 Minutes, http://www.amazon.com/dp/0672325675, and websites that you might like are http://w3schools.com/php/php_mysql_intro.asp http://www.tizag.com/mysqlTutorial or http://www.keithjbrown.co.uk/vworks/mysql . 4. Calling R from C. Notes on this come from Phil Spector's lecture notes at UC Berkeley. The composite version of Simpson's rule is a rough way to approximate an integral of some function, f. It goes back to English mathematician Thomas Simpson (1710Ð1761), who approximated the integral from a to b of f(x) dx by [(b-a)/6] [f(a) + 4f((a+b)/2) + f(b)]. This is the approximation you'd get by just dividing the interval (a,b) into 6 pieces, and using the left endpoint for the first piece, the right endpoint for the last piece, and the middle, (a+b)/2, for the other 4 pieces. For the composite Simpson's rule, you divide the interval not into 6 pieces but n pieces, where n is even, and get the integral from a to b of f(x) dx ~ h/3 [f(a) + 4f(a+h) + 2f(a+2h) + 4f(a+3h) + 2f(a+4h) + ... + 4f(b-h) + f(b)], where h = (b-a)/n. Note that the coefficients 4 and 2 alternate. The error in Simpson's rule is bounded in absolute value by h^4 (b-a) max[f^4(x); x in (a,b)]/180. Suppose we want to write this function f in R, but run the composite Simpson's rule in C, and call the C function from R. The key component is a C function called call_R. call_R takes as one of its arguments a pointer to a function, which is passed into the C environment as a list. The number and type of the arguments to f are also passed to call_R. As usual, when calling C from R, the results of the C function in the end are passed back to R not as a returned value, but through the argument list. It is typically easiest to divide the C program into three parts. 1) simp is the algorithm to implement the composite Simpson's rule, but it doesn't deal with issues pertaining to the interface between C and R. 2) sfunc is just a shell that uses call_R to have R evaluate the function f. 3) dosimp is just the interface, which is called by R and which calls simp. In simp.c, static char *sfunction; double simp(double(*func)(),double start,double stop,long n) { double mult,x,t,t1,inc; long i; inc = (stop - start) / (double)n; x = start; t = func(x); mult = 4.0; for(i=1; i