[R] How to catch warnings
Rainer M Krug
r.m.krug at gmail.com
Thu Nov 18 13:22:18 CET 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/18/2010 12:54 PM, Alaios wrote:
> Thanks a lot. Unfortunately browser() works pretty bad for me. As I am
> using Rkward this gives me a prompt while at the same time R console is
> blocked which make things not very easy.
First option:
you know where the error occurs, so enlarge the script window, so that
you can see the code you want to debug.
Second option:
Start a second rkward independent R session and debug from there.
I would suggest to contact the rkward mailing list, as one should at
least be able to scroll in the rkward windows while the prompt is shown.
Cheers,
Rainer
>
> Regards
> Alex
>
> --- On *Thu, 11/18/10, Rainer M Krug /<r.m.krug at gmail.com>/* wrote:
>
>
> From: Rainer M Krug <r.m.krug at gmail.com>
> Subject: Re: [R] How to catch warnings
> To: "Alaios" <alaios at yahoo.com>
> Cc: "Michael Bedward" <michael.bedward at gmail.com>, "Rhelp"
> <r-help at r-project.org>
> Date: Thursday, November 18, 2010, 11:37 AM
>
> On 11/18/2010 11:11 AM, Alaios wrote:
>> Dear Michael,
>> I would like to thank you for your reply. This line made things
> easier. One more question what If I want to halt or pause the
> program when a warning happens? Right now I get only a message
> printed but it would be nicer if the execution is paused so to try
> to print more values.
>
> What about the following? Is that what
>
> x <- 1:4
> y <- list(good=2:5, bad=3:5)
> for (yy in y) {
> tryCatch( x <- cbind(x, yy),
> warning=browser
> )
> }
>
> Cheers,
>
> Rainer
>
>
>> Best REgards
>
>> Alex
>
>> --- On Thu, 11/18/10, Michael Bedward <michael.bedward at gmail.com
> </mc/compose?to=michael.bedward at gmail.com>> wrote:
>
>> From: Michael Bedward <michael.bedward at gmail.com
> </mc/compose?to=michael.bedward at gmail.com>>
>> Subject: Re: [R] How to catch warnings
>> To: "Alaios" <alaios at yahoo.com </mc/compose?to=alaios at yahoo.com>>
>> Cc: "Rhelp" <r-help at r-project.org
> </mc/compose?to=r-help at r-project.org>>
>> Date: Thursday, November 18, 2010, 1:26 AM
>
>> Hi Alex,
>
>> Something like this ?
>
>> x <- 1:4
>> y <- list(good=2:5, bad=3:5)
>> for (yy in y) {
>> tryCatch( x <- cbind(x, yy),
>> warning=function(w) cat("problem values: ", yy, "\n")
>> )
>> }
>
>> Michael
>
>
>> On 18 November 2010 03:19, Alaios <alaios at yahoo.com
> </mc/compose?to=alaios at yahoo.com>> wrote:
>>> Hello when my code executes I receive the message that were some
> warnings. I want to catch warning messages at run time so to print
> some local variables and try to understand why this warning happens.
>>>
>>> I searched on internet and I tried withCallingHandlers(
>>> which seems to work but as I used Rkward the result is awful. I
> get a prompt to copy paste a value only while at the same time my
> background window with my code is not anymore accessible.
>>>
>>> Actually I get the warning that
>>> In f[cbind(shweights[, 1], shweights[, 2])] * shweights[, ... :
>>> longer object length is not a multiple of shorter object length
>>>
>>> and what I want is when the warning appear to be able to print
> the value shweights[,1] shweights[,2] to see what is going on.
>>>
>>> Any easier way to do that?
>>> Best REgards
>>> Alex
>>>
>>>
>>>
>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>>
>>> ______________________________________________
>>> R-help at r-project.org </mc/compose?to=R-help at 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.
>>>
>>>
>
>
>
>
>> [[alternative HTML version deleted]]
>
>
>
>
>> ______________________________________________
>> R-help at r-project.org </mc/compose?to=R-help at 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.
>
>
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa
Tel: +33 - (0)9 53 10 27 44
Cell: +27 - (0)8 39 47 90 42
Fax (SA): +27 - (0)8 65 16 27 82
Fax (D) : +49 - (0)3 21 21 25 22 44
Fax (FR): +33 - (0)9 58 10 27 44
email: Rainer at krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkzlGnoACgkQoYgNqgF2ego/kQCeOdnA6RTOV8aRIREOnOuu7HH4
EMsAn1ZLGaibFByPYbMqYCJQgYiZReHI
=mkOi
-----END PGP SIGNATURE-----
More information about the R-help
mailing list