[英]R directory path windows vs Mac
I have a number of R Projects which run on my Windows machine and I recently bought a Mac. 我有许多在Windows机器上运行的R项目,最近购买了一台Mac。
I would like to alternate between my Mac and Windows pc without changing code snippets all the time. 我想在Mac和Windows PC之间切换,而不一直更改代码段。
I use variables that serve as directory/path locations. 我使用充当目录/路径位置的变量。
For example: 例如:
temp_path <- 'C:/RCode/'
If I run this code on my Mac, I will obviously get an error. 如果我在Mac上运行此代码,显然会得到一个错误。
How can I get around this? 我该如何解决?
You can specify path based on OS using an if condition. 您可以使用if条件基于OS指定路径。 To find the OS you can use *.Platform$OS.type.
要查找操作系统,可以使用* .Platform $ OS.type。 Here is a sample code to make it work.
这是使其工作的示例代码。
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")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.