在调用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发布于 2015-03-16 21:10:50
我找到了一种解决方案,可以使用suppressMessages函数抑制消息,即使它不会抑制所有消息,只抑制那些发送到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'.发布于 2015-05-06 00:07:22
将render()封装在suppressMessages()中只会抑制plot_crop()函数抛出的message("cropping ", x)。为了隐藏pdfcrop本身的输出,有必要在内部系统调用中设置ignore.stdout = TRUE。我刚刚在GitHub上以knitr issue #1031的身份提交了此功能请求。
发布于 2020-06-12 20:22:59
对我来说起作用的(不是最好的解决方案)是将函数赋给一个变量。然后它将不会打印任何内容:
q = knitr::plot_crop(pdf_file,quiet = TRUE)https://stackoverflow.com/questions/29077093
复制相似问题