I got several responses from Liaw, Andy; David Homiak; Shige Song; ROGER
NGOUENET;Don MacQueen; and Xiaofei Wang. Many thanks to you guys help.
Following
is a summary of all the responses:
Original Message:
Hello, S-users:
I need to call a C subroutine in Splus simulations. As I just know a little
about C, this is hard to me. Can anyone give me a simple example of how to do
this, including if I need to compile the C subroutine first and how to pass the
parameters from the Splus function to the C subroutine.
Thanks and I appreciate your help,
Jingli Song
Dept. of Biostatistics
Emory University
Suggestions:
1.Splus Programmer's guide. (Splus 2000 or splus5 or splus6) can be accessed
online at ' www.insightful.com'.
2. Modern Applied Statistics with S-plus, (W.N. Venables and B. D. Ripley).
There is an online resource of this book. the website is:
http://www.stats.ox.ac.uk/pub/MASS3/
3. S Programming(B. D. Ripley), website:
http://www.stats.ox.ac.uk/pub/MASS3/Sprog/#OnLine
there also have availiable scripts file at:
http://www.stats.ox.ac.uk/pub/MASS3/Sprog/Sprog.zip
4. go to R website at: www.r-project.org
5. an brief introduction from David Homiak (with unix system).
Then hopefully your unix system includes a C compiler. I believe most do.
Here's a rough and partial outline.
If I recall correctly, compile with the -o option (to get only an
object file output, you don't need or want to get an executable file).
Put the output file in the same directory as the Splus function that
will call the C subroutine. Use the Splus CHAPTER command to make an
Splus shared object (should automatically get named S.so) from the C
object file. Actually, you may have to run the unix 'make' command
after the Splus CHAPTER command. Then, when you start Splus in that
directory, the C routine in S.so will be available.
Then, you have to write an Splus function that calls the C
subroutine. I've done this with fortran, but not C so I can't help
you with some of the C stuff.
|