Closed bschilder closed 1 year ago
These errors are written to C language 'stderr' but unfortunately this is not directly available within R. From the command line, on Linux, one could run a script script.R
and redirect stderr to a file
Rscript -f script.R 2> stderr.log
but probably your intention is something different.
Previously, Rsamtools used a 'hack' to remap fprintf(stderr, ...)
to R's error stream, with something like
DFLAGS = \
-Dfprintf=_samtools_fprintf \
-Dexit=_samtools_exit \
-Dabort=_samtools_abort
This would have captured samtools errors as R warnings, but unfortunately this functionality was lost when we shifted to using Rhtslib quite some time ago; perhaps @hpages has additional comment.
I don't think there's an easy way to capture what you'd like to do.
Hi Martin,
HTSlib uses a more sophisticated mechanism than Samtools for logging events: now everything goes thru the hts_log()
function defined in header file hts_log.h
. The function handles various levels of event severity: error, warning, debug, and trace. There's a macro defined for each level (hts_log_error()
, hts_log_warning()
, etc...). Each macro is a simple wrapper around hts_log()
.
Note that hts_log()
itself is not a macro, it's a real function, and it's not an inline function either, so I'm not sure why it's defined in a header file.
Anyways, this new mechanism and its implementation differ substantially from the plain fprintf(stderr, ...)
calls used all over the place in Samtools. I didn't investigate so I don't know how easy/hard it would be to come up with a hack similar to yours where all the events logged thru hts_log_error()
get captured as R warnings.
Ideas, suggestions, patches are welcome.
Thanks, H.
Personally I'm not planning to tweak Rhtslib to make the low-level C code in htslib spit output that is capturable from R but maybe someone else wants to give it a shot? If not, we can close this.
Thanks, H.
I recently posted an error I've been encountering with seqminer (here) but realized it seems to trace all the way back to tabix itself.
Regardless, in cases where I get the following kind of error...
...I'd like to wrap the function in a
tryCatch
and capture the messages so that I rerun it with the offending lines in theskip
argument. Something like:However, I can't seem to get the output into R. I've tried:
tryCatch
(above)capture.output
sink()
Do you know a way to extract this info?
Thanks, Brian
Session info