簡體   English   中英

使用R rmarkdown渲染功能時如何抑制pdfcrop打印?

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

我試圖在調用 R rmarkdown 渲染函數時抑制打印到由 pdfcrop 生成的 stdout 和 stderr,但不知道該怎么做。

我已經使用了 quiet 選項來抑制 pandoc 命令行執行的打印,但它不會抑制 pdfcrop 的打印。

有沒有人有一些提示來解決它?

這是我運行的腳本:

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

這是對渲染函數的調用:

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)

這是 test/out5.log 的內容:stdout(常規)和 stderr(粗體:** 之間)輸出

**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

我找到了一種使用抑制消息函數來抑制消息的解決方案,即使它不抑制所有消息,只抑制那些發送到 stderr 的消息。

以下是我的修改:

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))

現在所有發送到 stderr 的消息都被抑制了,但不是那些發送到我腳本的 stdout 的消息。

它仍然是那些與 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'.

suppressMessages()封裝render()只會抑制plot_crop()函數拋出的message("cropping ", x) 為了隱藏pdfcrop本身的輸出,有必要在內部系統調用中設置ignore.stdout = TRUE 我剛剛在 GitHub 上以knitr 問題 #1031 的形式提交了此功能請求。

對我有用的(不是最漂亮的解決方案)是將函數分配給一個變量。 它不會打印任何內容:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM