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

在基于OS的Rstudio中设置工作目录,r,operating-system,R,Operating System,我有一个非常基本的问题 我想根据Rstudio正在运行的操作系统(MAC、Windows)设置工作目录。您能否建议如何使用getwd()和setwd()来完成此操作?哪些函数可以在R中提供操作系统详细信息?您只需在控制台上键入Sys.info()即可获得操作系统详细信息。我目前没有访问R的权限,但我认为答案应该是这样的: a = Sys.info()[1] if( a == "Windows") { set the working dir in windows} if( a != "Window

我有一个非常基本的问题


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

您只需在控制台上键入
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()

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名称的第一个元素

检查此项:
Sys.info()[“sysname”]
提供系统名称,而不使用神奇常数(1)。您可以按名称或向量返回向量中的值。如果阅读R帮助,您将看到Sys.info()函数的返回是一个向量。无论如何,我试图尽可能地澄清答案,而且Prradep需要根据操作系统设置工作目录。所以需要神奇的常数!