[R] Souce macros help

rkevinburton at charter.net rkevinburton at charter.net
Mon Apr 6 00:41:51 CEST 2009


I was trying to understand some of the source in optimi.c and in the SANN source I see:

	SETCADR(OS->R_gcall, x);
	PROTECT_WITH_INDEX(s = eval(OS->R_gcall, OS->R_env), &ipx);
	REPROTECT(s = coerceVector(s, REALSXP), ipx);
	if(LENGTH(s) != n)
	    error(_("candidate point in optim evaluated to length %d not %d"),
		  LENGTH(s), n);

I think I need a little help it it is not too much to ask. Admitedly I could search for the definition of each of these macros and after some time decipher their meaning. But in an effort to save some time I am appealing to this group.

First, 

	SETCADR(OS->R_gcall, x);

I was unable to find thie function call in the sources it seems to be called everywhere so searches turn up many hits.

Second,

	PROTECT_WITH_INDEX(s = eval(OS->R_gcall, OS->R_env), &ipx);

I am assuming that this acutall calls the function pointed to by R_gcall. But, I am not sure where &ipx fits in and what PROTECT_WITH_INDEX does. I read the "wirting exstensions" documentation and this specific macro is dealt with in section 5.9.1 but I still am having a hard time understanding what is happening. Perhaps the added call to eval is confiusing me. I am assuing that this makes the function call.


Third,

	REPROTECT(s = coerceVector(s, REALSXP), ipx);

Again the vector ipx shows up. Would someone please help me to understand what this statement is doing?

Thank you for your time and patience.

Kevin



More information about the R-help mailing list