在外部程序中打开由R创建的文件

use*_*508 3 shell logging r

我希望R打开在我的程序中创建的文件.我的代码使用以下代码将日志文件保存到名为logFile的变量中.

logFile <- sprintf("../output/%s_%s_output%sof%s.log", str1, str2, str3, str4);
Run Code Online (Sandbox Code Playgroud)

我试图通过调用来访问shell函数

shell('%s',logFile);
Run Code Online (Sandbox Code Playgroud)

但是我说错了

In shell("%s", toFile) : '%s' execution failed with error code 127
Run Code Online (Sandbox Code Playgroud)

如何在完成写入文件后让我的程序打开该文件?

Jos*_*ien 7

你在找这样的东西吗?它工作得很好,至少在我的Windows机器上.

## An example temp file
ff <- paste0(tempfile(), ".txt")
write.table(head(mtcars), file=ff)

## Open the file with the program associated with its file extension
system2("open", ff)
Run Code Online (Sandbox Code Playgroud)

  • 在Windows框中,`shell.exec(ff)`也应该可以工作. (3认同)

Jer*_*y T 7

怎么样?

browseURL('view.xlsx')
Run Code Online (Sandbox Code Playgroud)