[R] last.warning and Sweave?

Romain Francois romain.francois at dbmail.com
Tue Jun 9 20:54:47 CEST 2009


Not sure either where the warning gets trapped, but you could use
something like that:

\documentclass{article}

\begin{document}

Test {\tt last.warning}

<<>>=
withCallingHandlers( {
    x <- log(-1)
}, warning = function(w){
    assign( "last.warning", w, env = baseenv() )
})
@

<<>>=
last.warning
@

\end{document}


Romain


Dieter Menne wrote:
> Ben Bolker <bolker <at> ufl.edu> writes:
>
>   
>>   Sweave does something clever with warnings, which I have so far been
>>     
> ...
>
>   
>>   I thought I could get around this with last.warning , but apparently
>> that doesn't work -- this file doesn't produce the desired output of
>> reproducing the last warning ...
>>
>> ========================
>> \documentclass{article}
>>     
>
> Missing \begin{document}
>  
>   
>> Test {\tt last.warning}
>>
>> <<>>=
>> x <- log(-1)
>> L <- last.warning
>> @
>>
>> <<>>=
>> L
>> @
>>
>> \end{document}
>> ==================
>>     
>
> No real answer, but I inserted a 
>
> print(exits("last.warning")) 
>
> which gives FALSE when sweaved, but TRUE when the tangled R file is run.
>
>
> Dieter
>
> ______________________________________________
> 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.
>
>
>   


-- 
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr




More information about the R-help mailing list