q() does not seem to take effect until control passes back to the top level
prompt.
I use this kind of pattern:
if (!file.exists("testfile"))
{
cat("This could should be executed\n")
q(n=123)
stop("Need to stop now!")
cat("This command should never be executed (and in fact won't be)\n")
}
Then, after returning to the top level, sqpe will stop, and the return
status will 123.
For return status under Windows, in the DOS command prompt, use
%ERRORLEVEL%. I use cygwin bash, where I can access the return status of
sqpe via $?, or something like ${PIPESTATUS[1]} if sqpe was in a piped command.
-- Tony Plate
mats pistol wrote:
I have seen the same type of behaviour with S+ v6 and
v7 in loops; S+ does execute commands which should not
be executed.
Your summary example is very good;
I have had this problem occur in Calculations which
affect the final answer!! Nowadays I festoon S+ code
with numerous checks to catch this type of problem.
You have raised a critical issue which has, for some
time, damaged my confidence in S+.
Repeated suggestions to Insightful have been met with
'its difficult'.
--- Dennis Fisher <fisher@plessthan.com> wrote:
Colleagues
I have encountered unexpected behavior manifested
through the quit
command (version 8 in both Linux and Windows Vista).
Basically, I
want to exit a script when certain conditions occur.
The file
testfile does not exist so the loop is entered.
Having executed the q
() command, I expected the final cat statement to
not be executed
(which is the case in R). I have solved the
particular situation in
which this occurred. However, I am interested in
understanding why
Splus behaves this way. It appears to be that the
problem resides in
how the contents of the loop are executed: if the
three commands
presently in the loop appear outside of the loop,
the quit commands
is executed at the time that it is called. So, it
appears that Splus
executes all the contents of the loop before the
quit is implemented
whereas R executes the commands in sequence.
if (!file.exists("testfile"))
{
cat("This could should be executed\n")
q(n=1)
cat("This command should never be
executed\n")
}
Also, n=1 in the q() command returns "status". In
Linux, this can be
recovered at the command line with echo $status.
However, I can't
get this to work in Windows (i.e., %status% does not
contain the
value) and I have been led to believe that this
command is not
implemented in Windows. Has anyone been successful
with this?
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com
__________________________________________________________
Sent from Yahoo! - the World's favourite mail http://uk.mail.yahoo.com
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|