当R脚本自动化不同的结果 [英] Different results when R script is automated

查看:247
本文介绍了当R脚本自动化不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的命令在PDF文件上执行ghostscript的。 (在 pdf_file 变量包含的路径PDF)

The following command executes ghostscript on a pdf file. (the pdf_file variable contains the path to that pdf)

bbox <- system(paste( "C:/gs/gs8.64/bin/gswin32c.exe -sDEVICE=bbox -dNOPAUSE -dBATCH -f", pdf_file, "2>&1" ), intern=TRUE)

执行后 BBOX 包括以下字符串。

GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 36 2544 248 2825
%%HiResBoundingBox: 36.395015 2544.659922 247.070032 2824.685914
Error: /undefinedfilename in (2>&1)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1147/1684(ro)(G)--   --dict:1/20(G)--   --dict:69/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 8.64: Unrecoverable error, exit code 1

此字符串然后按顺序操纵的BoundingBox的尺寸(36 2544 248 2825)被隔离并用于裁剪PDF文件。到目前为止,一切工作正常。

This string is then manipulated in order for the BoundingBox dimensions (36 2544 248 2825) to be isolated and used for cropping the pdf file. So far everything works ok.

然而,当我安排在任务管理器(使用Rscript.exe或Rcmd.exe批)这个脚本,或者当脚本是R块内,我preSS 针织HTML ,BBOX变得缺乏BoundingBox的信息,下面的字符串,使其无法使用:

However, when I schedule this script in Task Manager (using Rscript.exe or Rcmd.exe BATCH), or when the script is inside an R chunk and I press knit HTML, bbox gets the following character string which lacks the BoundingBox information, and makes it unusable:

GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Error: /undefinedfilename in (2>&1)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1147/1684(ro)(G)--   --dict:1/20(G)--   --dict:69/200(L)--
Current allocation mode is local
Last OS error: No such file or directory

我怎样才能克服这个问题,该脚本运行的自动化?

How can I get over this problem and have the script run automated?

(脚本来自于接受的答案来这个问题

(The script comes from the accepted answer to that question)

推荐答案

2 - ;&放大器; 1 在命令的末尾添加发送到的ghostscript间preTER,而不是shell。 的Ghostscript间$ P $点一个文件,因此错误。我曾经将procmon看看进程创建:

The 2>&1 you add at the end of the command is sent to the ghostscript interpreter, not the shell. Ghostscript interprets it a file, hence the error. I used procmon to look at the process creation:

为了使外壳间preT,您必须preFIX用命令的 CMD / C ,像这样

To make the shell interpret it, you must prefix the command with cmd /c, like this

> bbox <- system(paste("cmd /c C:/Progra~1/gs/gs9.07/bin/gswin64c.exe -sDEVICE=bbox -dNOPAUSE -dBATCH -q -f",pdf_file,"2>&1"), intern=TRUE)
> print (bbox)
[1] "%%BoundingBox: 28 37 584 691"                                  "%%HiResBoundingBox: 28.997999 37.511999 583.991982 690.839979"

这篇关于当R脚本自动化不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆