[R] `UNPROTECT' and `return'

Timur Elzhov Timur.Elzhov at jinr.ru
Wed Feb 12 17:18:03 CET 2003


Dear R experts,

In all R functions written in C one must unprotect
result before returning them:

  {
      ...
      UNPROTECT(1)  /* unprotecting `ans' */

      return ans;
  }

Why does one shure that memory occupied by `ans'
won't be used by R immediately after unprotecting?

Ok, is the next construction also absolutely safe?
  {
      ...
      UNPROTECT(1)  /* unprotecting `ans' */

      PROTECT( val = ans )
      ...
  }

Thanks a lot!


--
WBR,
Timur.




More information about the R-help mailing list