如何在Windows 10上端到端使用R编写EPS文件?

如何解决如何在Windows 10上端到端使用R编写EPS文件?

这是为科学论文投稿而生成准备发布的EPS文件的可怕时间。数据是绘图的线条艺术数字,位于R(RStudio和R版本4.02结合)中。我曾经在一个人口众多的Linux机器上遇到过这个挑战。今天,我使用的是仅四个月前安装的x64位Windows 10。

代码是:

require(graphics)
options(printcmd = 'gsprint -ghostscript gswin64')
postscript(file = tempfile("Rps."),print.it=TRUE,family="sans")
plot_grid(image1Agg,image1Bgg,image1Cgg,labels = c('A','B','C'),label_size = 12,label_fontfamily = "sans")
dev.off()

我为Win10安装了最新版本的gsview和ghostscript,并为避免使用目录结构和“程序文件”来避免字符混淆的烦恼,我将这两组二进制文件的路径都添加到PATH。

在RStudio的控制台上执行代码时,我得到...

Warning message:
In dev.off() : error from postscript() in running:
    gsprint -ghostscript gswin64 C:\Users\yewro\AppData\Local\Temp\Rtmp0Yqsfg\Rps.17d065ef330

如果我在Windows Commmand上执行此操作,则会看到更多内容(正如我期望的R postscript()文档所述):

Copyright (C) 2003-2006,Ghostgum Software Pty Ltd.  All Rights Reserved.
2006-02-24 gsprint 1.9
GPL Ghostscript 9.53.1 (2020-09-14)
Copyright (C) 2020 Artifex Software,Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Loading NimbusSans-Regular font from %rom%Resource/Font/NimbusSans-Regular... 4216964 2747487 1743856 440491 2 done.
Loading NimbusSans-Bold font from %rom%Resource/Font/NimbusSans-Bold... 4283076 2921313 1764056 451768 2 done.
Loading NimbusSans-Italic font from %rom%Resource/Font/NimbusSans-Italic... 4470388 3128353 1764056 459255 2 done.
Loading NimbusSans-BoldItalic font from %rom%Resource/Font/NimbusSans-BoldItalic... 4677900 3341192 1784256 470184 2 done.
Loading StandardSymbolsPS font from %rom%Resource/Font/StandardSymbolsPS... 4771268 3431892 1784256 477717 2 done.
GPL Ghostscript 9.53.1: **** Could not open the file 000002dc .
Error: /invalidfileaccess in --showpage--
Operand stack:
   1   true
Execution stack:
   %interp_exit   .runexec2   --nostringval--   showpage   --nostringval--   2   %stopped_push   --nostringval--   showpage   showpage   false   1   %stopped_push   1990   1   3   %oparray_pop   1989   1   3   %oparray_pop   1988   1   3   %oparray_pop   showpage   1977   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   showpage   --nostringval--   2   %stopped_push   --nostringval--   showpage   1840   0   3   %oparray_pop   showpage   showpage
Dictionary stack:
   --dict:733/1123(ro)(G)--   --dict:0/20(G)--   --dict:105/200(L)--
Current allocation mode is local
Last OS error: Permission denied
Current file position is 5271
GPL Ghostscript 9.53.1: Unrecoverable error,exit code 1

我尝试过的各种情况:

  1. 检查发现生成的.Rps文件确实存在。
  2. 在比代码更本地的目录(即文档和当前工作环境或RStudio)中生成.Rps文件。
  3. 试图从Windows命令运行gsprint,在一个实例中指定绝对路径,然后在第二个实例中依赖PATH。
  4. 我分别使用了gswin64和gswin64c,GUI和控制台。

从阅读论坛中,我知道如果要处理的文件不存在(我认为是unfinfinnedfilename),ghostscript会引发不同错误,因此我相信它会看到 ,但是此操作会引发无效文件访问,而操作系统会引发“权限被拒绝”。因此,我也尝试过:

  1. 以管理员身份在Windows命令上运行上述操作(此Windows回答sudo吗?!)。

我已经浏览了R postscript()文档,并且对示例下的条目感到有些困惑:

## On Windows:
options(printcmd = 'redpr -P"\\printhost\lw"')
postscript(file = tempfile("Rps."),print.it = TRUE)
# produce the desired graph(s)
dev.off()              # send plot file to the printer
## alternative using GSView 4.x :
options(printcmd = '/GhostGum/gsview/gsprint -query')

注意:我还没有尝试过:options(printcmd ='redpr -P“ \ printhost \ lw”'),首先,该行包含无效的R语法,其次,我有更多使用GSView的经验,因此立即被替代方法吸引。

有趣的是,当查看Ghostscript指令时,gsprint -query指的是“显示打印机设置对话框”。在命令行上调用它,它告诉我使用-ghostscript,这是我要求它执行的操作。

总的来说,运气好的情况下生成EPS文件,但我感觉它的命令参数与gswin64c有关。非常感谢您的帮助。

解决方案 多亏了KenS,如果没有他们的投入,我可能仍会进行故障排除。原来是Ghostscript的版本是问题所在(请参阅评论和答案)。为了生成用于发布的EPS图像,我在R中使用了另一种方法:

在RStudio控制台上(不在RMarkdown文档中):

library("cowplot")
#code for my ggplot2 objects here: image1Agg,and image1Cgg
#for example

image1Cgg <- ggplot(combinedFrequenciesDF_ByClass,aes(x=reorder(displayDescription,-Frequency),y=Frequency)) + geom_bar(stat="identity") + theme_classic() + theme(text = element_text(size = 10),axis.text.x = element_text(angle = 45,hjust=1),axis.text = element_text(color="black")) + xlab("First Prescription (Drug Class)") + ylab("Patients") + scale_y_continuous(expand = expansion(mult = c(0,.1)))

image1Grid <- plot_grid(image1Agg,labels= c("(a)","(b)","(c)"),label_size = 10,ncol = 1,vjust = 1,hjust=0.03)
image1Grid #in the RStudio console so it appears in the RStudio Plots window
ggsave("image1.eps",units="cm",width=15,height=20,device="eps")

在装有最新GSView和Ghostscript的Windows 10上,以上内容生成了EPS文件。我不会假装知道ggsave如何使用后记,我只知道在我的OS上正确安装了这两个程序,它可以工作。我还发现cow_plot替代方法有效:

save_plot("image1.eps",image1Grid,base_height=7.9,base_width=5.9) #this is in inches

save_plot和ggsave均生成默认情况下15厘米宽的EPS图像,该图像在左右边缘留有3厘米。我希望这对其他人有帮助。

解决方法

Ghostscript的最新版本(很遗憾,您已从stdout中删减了该版本,但由于是(C)2020,所以它必须是最近的版本)已更改了默认行为,因为存在安全漏洞。现在默认设置是在SAFER模式下运行(以前的默认设置是NOSAFER)。这意味着不允许PostScript程序打开/读取/写入/删除磁盘上的文件。

看起来您正在运行的文件在尝试写入文件时遇到了invalidfileaccess错误。 Ghostscript命令行上的输出文件未提及要写入'00002dc'的文件名,这是Ghostscript推断应该允许文件访问的唯一方法。基本上,如果文件不是在命令行上命名的,并且您没有告诉GS它具有读取/写入给定目录的权限,则不允许访问该文件。

您可以尝试使用-dNOSAFER,我不知道如何将其添加到gsprint中,这不是Ghostscript的一部分,但可能(读取gsprint.htm文件)-option“ -dNOSAFER”可能有效。 / p>

我不会真的建议您将其作为长期解决方案。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-