On 11-08-05 7:19 AM, Prof Brian Ripley wrote:
On Fri, 5 Aug 2011, Duncan Murdoch wrote:

On 11-08-05 12:09 AM, Alexandre Aguiar wrote:
Hi,

When a function returns a SEXP of type LGLSXP (logical) to signal whether
it succeeded or failed, how is it intrepreted? Is it like C where SUCCESS
= 0 or other value?

Usually TRUE is used to signal success.  TRUE is non-zero.

Strictly, TRUE is not numeric: it is coerced to 1 when coerced to a
numeric value.

Another point I should have made: using logical values to signal success is fairly rare among R functions. More common is to trigger an error or return NULL or a zero length vector on failure. Most R functions return something other than TRUE on success, even if they are called for their side effects (e.g. setwd() returns the old directory, plot.new() returns NULL on success).

Duncan Murdoch


If you are looking at C level at the SEXP: don't as the internal
representation is just that: 'internal and subject to change'.

There is no C convention to use 0 for success: that is a Unix
convention for status values as returned by exit(), and even there the
man page will advise you to use the symbol EXIT_SUCCESS.  Other OSes
do differ.


Duncan Murdoch

______________________________________________
[email protected] 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.



______________________________________________
[email protected] 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.

Reply via email to