【发布时间】:2017-04-20 07:51:29
【问题描述】:
我想监控 R 中在各个页面上生成的图形的基本质量,例如每页的字节大小,... 我现在只能对平均页面进行质量保证,请参阅以下章节。 我认为该任务必须有一些内置的东西而不是平均措施。
在Rplots.pdf 中生成 4 个页面的代码,我想知道此处输出中每个页面的字节大小;也欢迎页面输出的任何其他统计信息;
您可以通过对象here 获得基本的内存监控,但我希望它与 PDF 中的输出相对应
# https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/plot.html
require(stats) # for lowess, rpois, rnorm
plot(cars)
lines(lowess(cars))
plot(sin, -pi, 2*pi) # see ?plot.function
## Discrete Distribution Plot:
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
main = "rpois(100, lambda = 5)")
## Simple quantiles/ECDF, see ecdf() {library(stats)} for a better one:
plot(x <- sort(rnorm(47)), type = "s", main = "plot(x, type = \"s\")")
points(x, cex = .5, col = "dark red")
## TODO summarise here the byte size of figures in the figures (1-4)
# Output: Rplot.pdf where 4 pages; I want to know the size of each page in bytes
我目前正在命令行中进行基本的质量保证,但想将其中一些移到 R 中,以便更快地观察错误。
预期输出:字节大小,例如ls -l 的第 4 列
获取输出文档中平均单个页面的字节大小
限制
- 要求页面中数据的同质性。此方法仅适用于所有页面均来自同一样本的情况。 否则很麻烦,因为它只是平均的,没有描述个别现象。 其他可能的弱点
- PDF 元素和元数据。整体考虑 pdf 文件,而不是关注图形对象本身。所以这限制了绝对值的使用,因为文件大小还包含标题和其他与图形对象无关的元数据。
代码
filename <- "main.pdf"
filesize <- file.size(filename)
# http://unix.stackexchange.com/q/331175/16920
pages <- Rpoppler::PDF_info(filename)$Pages
# print page size (= filesize / pages)
pagesize <- filesize / pages
## data of example file
num 7350960
int 62
num 118564
输入:任何 62 页的文档
输出:平均单个页面大小(118564)
测试and's答案
输出,但您无法轻松地将输入更改为您想要的 pdf 文件
files size_bytes
[1,] "./test_page_size_pdf/page01.pdf" "4,123,942"
[2,] "./test_page_size_pdf/page02.pdf" " 4,971"
[3,] "./test_page_size_pdf/page03.pdf" " 4,672"
[4,] "./test_page_size_pdf/page04.pdf" " 5,370"
输入:任何 64 页的文档
预期输出:67 (= 64 + 3) 页,而不是 4 页分析
R:3.3.2
操作系统:Debian 8.5
【问题讨论】:
-
file.size("Rplots.pdf)将给出等于ls -l的文件大小(第 4 列),但它不会给出 每页的字节大小 -
你用什么程序来创建pdf?