I have a daily generated report in which I put a check using stopifnot. Unfortunately I didn?t check the effect very well, turns out that if the condition checked fails this is not shown in the knitr output (I only get an error much later due to a missing object). So my question is, what is the correct way to use assertions in a <filename>.Rnw file. I want to perform a check, and if it fails everything should stop with a message I can generate. Thanks, Best, Bart
knitr and stopifnot replacement.
4 messages · Duncan Murdoch, Bart Kastermans, Yihui Xie
On 22/08/2014, 6:02 AM, Bart Kastermans wrote:
I have a daily generated report in which I put a check using stopifnot. Unfortunately I didn?t check the effect very well, turns out that if the condition checked fails this is not shown in the knitr output (I only get an error much later due to a missing object). So my question is, what is the correct way to use assertions in a <filename>.Rnw file. I want to perform a check, and if it fails everything should stop with a message I can generate.
One of the differences between knitr and Sweave is that knitr handles errors, and Sweave doesn't. I expect there's some knitr option to tell it to quit in case of error (a hook?), but you'll have to check the documentation to find it. Duncan Murdoch
On 22 Aug 2014, at 12:39, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
On 22/08/2014, 6:02 AM, Bart Kastermans wrote:
I have a daily generated report in which I put a check using stopifnot. Unfortunately I didn?t check the effect very well, turns out that if the condition checked fails this is not shown in the knitr output (I only get an error much later due to a missing object). So my question is, what is the correct way to use assertions in a <filename>.Rnw file. I want to perform a check, and if it fails everything should stop with a message I can generate.
One of the differences between knitr and Sweave is that knitr handles errors, and Sweave doesn't. I expect there's some knitr option to tell it to quit in case of error (a hook?), but you'll have to check the documentation to find it.
Thanks; that helped me to find the exact right option: <<filelist, error=FALSE>>= # check all files exist before continuing stopifnot(all(sapply(files, file.exists))) @
Duncan Murdoch
Yep, that is exactly the answer. Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Web: http://yihui.name
On Fri, Aug 22, 2014 at 6:35 AM, Bart Kastermans <kasterma at kasterma.net> wrote:
On 22 Aug 2014, at 12:39, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
On 22/08/2014, 6:02 AM, Bart Kastermans wrote:
I have a daily generated report in which I put a check using stopifnot. Unfortunately I didn?t check the effect very well, turns out that if the condition checked fails this is not shown in the knitr output (I only get an error much later due to a missing object). So my question is, what is the correct way to use assertions in a <filename>.Rnw file. I want to perform a check, and if it fails everything should stop with a message I can generate.
One of the differences between knitr and Sweave is that knitr handles errors, and Sweave doesn't. I expect there's some knitr option to tell it to quit in case of error (a hook?), but you'll have to check the documentation to find it.
Thanks; that helped me to find the exact right option: <<filelist, error=FALSE>>= # check all files exist before continuing stopifnot(all(sapply(files, file.exists))) @