【问题标题】:Mac to Windows Compatibility with an R Script Calling BashMac 到 Windows 与 R 脚本调用 Bash 的兼容性
【发布时间】:2016-10-15 09:17:45
【问题描述】:

当前脚本

我在 Mac OSX 工作。我有一个 R 脚本,我喜欢用它来组织我的文件并通过 LaTex 生成 .pdf。为了 (1) 使用 LaTeX 生成 .pdf 并 (2) 操作一些文件和目录,我使用 R 中的 Bash 脚本和system("")

从 Mac 到 Windows

我想将此 R 脚本(一旦编译为可执行文件)提供给对编程一无所知并使用 Windows 的人。我不知道 Windows 提示命令如何工作以及它使用什么语言。恐怕(1)我不能在 Windows 上使用函数 system("") 和(2)我不能使用诸如 system("rm dir/file.txt") 之类的 bash。

问题

为了使我的脚本与 Windows 兼容,您认为对我来说最简单的方法是什么(鉴于我对 Windows 一无所知)?我可以在 Windows 上使用 R 中的 system("") 和 Bash 吗?

【问题讨论】:

  • 根据您想要执行的操作,使用 R 命令代替 system / bash 命令可能就足够了,以便自动处理平台差异。工具包有texi2pdf 用于将latex 转换为pdf。 ?files 中记录的 R 命令也可能有所帮助。

标签: r windows bash macos compatibility


【解决方案1】:

我认为最好的解决方案是分别处理这两种情况(请记住,windows 路径也不同于 unix 路径)。

if(.Platform$OS.type == "unix") {
  system("rm dir/file.txt")
  [...]
} 
else {
  system("DEL /Q dir\file.txt")
  [...]
}

在 windows cmd 中搜索 unix 等效命令应该没有问题。

另外请记住,如果您需要 R 脚本来执行 LaTeX 二进制文件,由于 LaTeX 具有巨大的依赖关系,它几乎会扼杀可移植性。

【讨论】:

    猜你喜欢
    • 2015-10-14
    • 2017-01-17
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 2013-06-06
    相关资源
    最近更新 更多