在R Studio中使用file.show打开PDF [英] Opening PDF within R studio using file.show

查看:224
本文介绍了在R Studio中使用file.show打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个在Swirl中的R中运行的R教程. 我正在尝试在R中打开特定的PDF文件. 我正在使用:

I am making making an R tutorial that runs in R within Swirl. I am trying open specific PDF files within R. I am using:

file.show(paste(getwd(),"/cv.pdf",sep=""), title="some title")

但是显示如下:

它不显示PDF文件.对于TXT文件效果很好.

It does not show PDF file. Works well for TXT file.

我正在运行OSX 10.11.1.默认的PDF查看器为预览",并且我没有安装Adobe Reader.是否可以通过R脚本打开PDF文件?

I am running OSX 10.11.1. Default PDF viewer is "Preview" and I do not have Adobe Reader installed. Is there a way I can have PDF file opened up through an R script?

推荐答案

file.show()仅用于打开文本文件.如果您想打开PDF,并且知道要在哪个平台上部署脚本-如果只是OS X计算机,这不是问题,但是您将共享本教程吗?-您可以使用

file.show() is only designed to open text files. If you'd like to open PDFs and you know which platform you'll be deploying the script on—not a problem if it's just your OS X machine, but will you be sharing this tutorial?—you can use system2() to run any command the shell can, including Preview.app.

要在OS X系统的默认PDF查看器中打开PDF,请执行以下操作:

To open a PDF in your OS X system's default PDF viewer:

system2('open', args = 'myfile.pdf', wait = FALSE)

要专门在预览"中打开PDF,请执行以下操作:

To open a PDF specifically in Preview:

system2('open', args = c('-a Preview.app', 'myfile.pdf'), wait = FALSE)

请注意,如果要从与PDF不同的目录中执行脚本,则需要提供完整路径,而不仅仅是文件名.

Note that you'll need to give a full path, rather than just a file name, if you're executing the script from a different directory to your PDF.

这篇关于在R Studio中使用file.show打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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