hi R wizards: I think it would be a good idea for me to use basic argument checking (type, length) in function calls via an assert() like function. How do people usually do this? Should I define my own "assert()" function (or are there some predefined assertions)? If I write my own assert, is it possible to print out the R internal call stack? thanks. (?assert and google "assert R" and V+D index do not point me the right way.) regards, /iaw
I often use stopifnot(). -roger ivo welch wrote:> > hi R wizards: I think it would be a good idea for me to use basic > argument checking (type, length) in function calls via an assert() like > function. How do people usually do this? Should I define my own > "assert()" function (or are there some predefined assertions)? If I > write my own assert, is it possible to print out the R internal call > stack? thanks. > > (?assert and google "assert R" and V+D index do not point me the right > way.) > > regards, /iaw > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
On Tue, 06 Apr 2004 15:21:12 -0400, ivo welch <ivo.welch at yale.edu> wrote :>hi R wizards: I think it would be a good idea for me to use basic >argument checking (type, length) in function calls via an assert() like >function. How do people usually do this? Should I define my own >"assert()" function (or are there some predefined assertions)? If I >write my own assert, is it possible to print out the R internal call >stack? thanks. > >(?assert and google "assert R" and V+D index do not point me the right way.)The stopifnot() function does pretty much what assert() does in other languages. Duncan Murdoch
On Tue, 6 Apr 2004, ivo welch wrote:> > hi R wizards: I think it would be a good idea for me to use basic > argument checking (type, length) in function calls via an assert() like > function. How do people usually do this? Should I define my own > "assert()" function (or are there some predefined assertions)? If I > write my own assert, is it possible to print out the R internal call > stack? thanks. >In the R testing suite the stopifnot() function does this. After stopping, traceback() will print out the R stack trace. A more elegant solution would use the new R condition mechanism and allow assertion failures to be caught independently of errors. -thomas