gpt4 book ai didi

linux - 检测操作系统并在 R 中适当更改路径

转载 作者:可可西里 更新时间:2023-11-01 10:36:41 24 4
gpt4 key购买 nike

我的电脑上安装了两个操作系统 - windows 和 linux。当我在 Windows 中编写脚本然后尝试在 Linux 上运行它们时,我必须更改每条路径。

例如,要在 Windows 中设置我的工作目录,我必须键入 setwd("d://MyStatistics")

但是,在 linux 中,此命令是 setwd("/media/55276F9D5951EC83/MyStatistics")

是否可以自动检测当前操作系统,如果来自其他系统则更改路径?

最佳答案

使用 if 条件来测试 R.version$platform.Platform$OS.typ

# It's as simple as...
path <- "/media/55276F9D5951EC83/MyStatistics"
if( .Platform$OS.type == "windows" )
path <- "d:\\MyStatistics"

setwd( path )

关于linux - 检测操作系统并在 R 中适当更改路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22423020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com