【问题标题】:R directory path windows vs MacR 目录路径 windows vs Mac
【发布时间】:2019-06-15 21:45:01
【问题描述】:

我有许多在我的 Windows 机器上运行的 R 项目,我最近买了一台 Mac。

我想在我的 Mac 和 Windows 电脑之间切换,而无需一直更改代码 sn-ps。

我使用充当目录/路径位置的变量。

例如:

temp_path <- 'C:/RCode/'

如果我在我的 Mac 上运行这段代码,我显然会得到一个错误。

我该如何解决这个问题?

【问题讨论】:

标签: r windows macos portability


【解决方案1】:

您可以使用 if 条件指定基于操作系统的路径。要查找操作系统,您可以使用 *.Platform$OS.type。 这是使它工作的示例代码。

OS <- .Platform$OS.type

if (OS == "unix"){
  temp_path <- "~/RCode/" # MAC file path
} else if (OS == "windows"){
  temp_path <- "C:/RCode/" # windows file path
} else {
  print("ERROR: OS could not be identified")
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 2021-07-18
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    相关资源
    最近更新 更多