【问题标题】:Set working directory in Rstudio based on OS [duplicate]基于操作系统在Rstudio中设置工作目录[重复]
【发布时间】:2015-09-15 14:22:48
【问题描述】:

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

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

【问题讨论】:

标签: r operating-system


【解决方案1】:

您只需在控制台输入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)。
  • 您可以通过名称或向量返回向量内的值。如果您阅读 R 帮助,您会看到 Sys.info() 函数的返回是一个向量。无论如何,我试图尽可能地澄清答案,Prradep 还需要根据操作系统设置工作目录。所以需要神奇的常数!
猜你喜欢
  • 2015-09-05
  • 2014-08-25
  • 2018-06-03
  • 1970-01-01
  • 2011-12-22
  • 1970-01-01
  • 2011-09-02
  • 2011-07-08
  • 1970-01-01
相关资源
最近更新 更多