【发布时间】:2015-09-15 14:22:48
【问题描述】:
我有一个非常基本的问题。
我想根据 Rstudio 运行的操作系统(MAC、Windows)设置工作目录。您能否建议如何使用getwd() 和setwd() 来完成这项工作?哪些函数可以在 R 中提供操作系统详细信息?
【问题讨论】:
标签: r operating-system
我有一个非常基本的问题。
我想根据 Rstudio 运行的操作系统(MAC、Windows)设置工作目录。您能否建议如何使用getwd() 和setwd() 来完成这项工作?哪些函数可以在 R 中提供操作系统详细信息?
【问题讨论】:
标签: r operating-system
您只需在控制台输入Sys.info() 即可获取操作系统详细信息。我目前无法访问 R,但我认为答案应该是这样的:
a = Sys.info()[1]
if( a == "Windows") { set the working dir in windows}
if( a != "Windows") { set the working dir in other OS}
Sys.info() 返回一个包含以下值的向量,您也可以在?Sys.info 的帮助中找到这些值:
sysname
The operating system name.
release
The OS release.
version
The OS version.
nodename
A name by which the machine is known on the network (if any).
machine
A concise description of the hardware, often the CPU type.
login
The user s login name, or "unknown" if it cannot be ascertained.
user
The name of the real user ID, or "unknown" if it cannot be ascertained.
effective_user
The name of the effective user ID, or "unknown" if it cannot be ascertained. This may differ from the real user in ‘set-user-ID’ processes.
您可以返回操作系统名称的第一个元素。
【讨论】:
Sys.info()["sysname"] 为您提供系统名称,而无需使用神奇的常量 (1)。