You might try to use "on.exit" or "stop"?

# on.exit
if (nAssetPositions != nAssetPrices) {
               on.exit(cat("Different number of assets! "\n"))
    }

# stop
if (nAssetPositions != nAssetPrices) {
               stop("Different number of assets!")
    }

You could find these in "S programming" by W.N Venables and B.D. Ripley

Chunhao


Quoting Bill Cunliffe <[EMAIL PROTECTED]>:

For example, based on a certain condition, I may want to exit my code early:



            # Are there the same number of assets in "prices" and
"positions"?

            if (nAssetPositions != nAssetPrices) {

                        cat("Different number of assets! \n\n")

                        <exit function>

            }



I have searched, but not found, a way of forcing a function to exit.  Any
help greatly appreciated.


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.


______________________________________________
R-help@r-project.org 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