【问题标题】:Alter file.show() behaviour改变 file.show() 行为
【发布时间】:2013-05-08 20:38:49
【问题描述】:

我在 Mac 上的 RStudio 中运行 file.show(),如下所示:

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

这做了两件事:

  1. 打开我的文件.pdf

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

    options()$pdfviewer
    

返回:

"/usr/bin/open"

我怎样才能阻止 (2) 发生?

【问题讨论】:

  • 您需要详细说明您的工作环境。例如,这会返回什么:options()$pdfviewer。我在 Mac 中得到了不同的行为(但没有运行 RStudio。)
  • 问题已更新,来自options()$pdfviewer

标签: r file-io rstudio


【解决方案1】:

如果您只想在 Mac 上通过 RStudio 打开 PDF 文件,最简单的方法(据我所知)是使用 system 函数:

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

例如它被 Biobase 中的openPDF 使用(参见here

我不知道如何更改 file.show 行为以防止在 RStudio 中打开空白文件。我认为这与您可以在手册here 上看到的The R.app Mac OS X GUI uses its internal pager irrespective of the setting of pager. 有关。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 2020-12-17
    相关资源
    最近更新 更多