2013-05-08 71 views
2

我在Mac上运行file.show()在RStudio,像这样:阿尔特file.show()行为

filename <- "/Users/me/reports/myfile.pdf" # replace with file location/name 
file.show(file.path(filename), title="My File") 

这做了两两件事:

  1. 打开我的file.pdf

  2. 在RStudio中打开一个名为“我的文件”的空白文件。

    options()$pdfviewer 
    

回报:

"/usr/bin/open" 

如何停止(2)发生?

+0

您需要更多地指定您的工作环境。例如,这会返回什么:'options()$ pdfviewer'。我在Mac中获得了不同的行为(但没有运行RStudio。) – 2013-05-09 00:02:12

+0

更新了出错的选项()$ pdfviewer' – luciano 2013-05-09 19:01:09

回答

0

如果你想简单地打开通过RStudio PDF文件在Mac上最简单的方法(据我所知)是使用system功能:

filename <- "/Users/me/reports/myfile.pdf" 
pdf <- getOption("pdfviewer") # same as options()$pdfviewer 
cmd <- paste(pdf,filename) 
system(cmd) 

例如它由openPDF (参见here

我不知道一种方法来改变file.show行为,以防止在RStudio中打开空白文件。我认为它与The R.app Mac OS X GUI uses its internal pager irrespective of the setting of pager.有关,你可以在手册here上看到。

注意:它在Windows机器上不同,请直接使用shell.exec(filename)