简体   繁体   中英

How to suppress pdfcrop printing when using R rmarkdown render function?

I tried to suppress printing to the stdout and stderr generated by pdfcrop when calling R rmarkdown render function but do not know how to do it.

I already used the quiet option to suppress printing of pandoc command line execution, but it does not suppress printing of pdfcrop.

Is anyone has some tip to fix it?

Here is the script I run:

Rscript RNASeq_QC_run.R -v 1 --count ~/devel/R/projects/rnaseq_qc/data/DataTest_Count_expression_generic2.txt  --format generic --design ~/devel/R/projects/rnaseq_qc/data/DataTest_Design.txt --outdir test/out5 &>test/out5.log

Here is the call to render function:

generic_report_path <- system.file("report", "QC_RNASeq_Count_generic.Rmd", package="qc4rnaseq")
generic_report_file <- paste(unlist(strsplit(basename(generic_report_path),".Rmd")), ".pdf", sep="")
render(input=generic_report_path, output_format="pdf_document", output_file=generic_report_file, output_dir=outdir_abs_path, intermediates_dir=outdir_abs_path, quiet=TRUE)

Here is the content of test/out5.log: both stdout (regular) and stderr (in bold: between **) output

**cropping /private/tmp/qc4rnaseq_run/test/out5/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-2-1.pdf**
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `/private/tmp/qc4rnaseq_run/test/out5/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-2-1.pdf'.
**cropping /private/tmp/qc4rnaseq_run/test/out5/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-3-1.pdf**
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `/private/tmp/qc4rnaseq_run/test/out5/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-3-1.pdf'.
**cropping /private/tmp/qc4rnaseq_run/test/out5/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-4-1.pdf**
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `/private/tmp/qc4rnaseq_run/test/out5/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-4-1.pdf'.
Execution time :  7.120109 seconds

I found one solution to suppress messages using the suppressMessages function even though it does not suppress all messages, only those sent to the stderr.

Here are my modifications:

suppressMessages(render(input=generic_report_path, output_format="pdf_document", output_file=generic_report_f
ile, output_dir=outdir_abs_path, intermediates_dir=outdir_abs_path, quiet=TRUE))

Now all the messages sent to the stderr are suppressed but not those sent to the stdout of my script.

It still remains those printing related to pdfcrop:

PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `/private/tmp/qc4rnaseq_run/test/out7/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-2-1.pdf'.
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `/private/tmp/qc4rnaseq_run/test/out7/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-3-1.pdf'.
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `/private/tmp/qc4rnaseq_run/test/out7/QC_RNASeq_Count_generic_files/figure-latex/unnamed-chunk-4-1.pdf'.

Encapsulating render() in suppressMessages() will only suppress the message("cropping ", x) thrown by the plot_crop() function. To also hide the output from pdfcrop itself, it would be necessary to set ignore.stdout = TRUE in the internal system call. I have just submitted this feature request as the knitr issue #1031 on GitHub.

What worked for me (not the most pretty solution) is to assign the function to a variable. It won't print anything then:

q = knitr::plot_crop(pdf_file,quiet = TRUE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM