在Rstudio中基于OS设置工作目录

时间:2015-06-29 07:43:20

标签: r operating-system

我有一个非常基本的问题。

我想根据运行Rstudio的操作系统(MAC,Windows)设置工作目录。您能否建议如何使用getwd()setwd()来完成此操作?哪些功能可以在R中提供OS详细信息?

1 个答案:

答案 0 :(得分:2)

只需在控制台输入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.

您可以返回OS名称的第一个元素。