是否可以识别是否在unix或windows环境中运行R.

Sam*_*ert 0 r

我需要为我的代码设置不同的路径,具体取决于它是在windows还是unix中运行.我目前设置它,以便用户在运行之前必须更改变量"Renvironment",如下所示.

Renvironment <- "windows"

if (Renvironment == "windows") {
  working_dir <- "windows_path..."
  function_library <- "windows_path..."
} else if (Renvironment == "unix") {
  working_dir <- "unix_path..."
  function_library <- "unix_path..."
}
Run Code Online (Sandbox Code Playgroud)

我想知道是否有默认的R环境变量,我可以使用它来保存用户必须记住手动更改变量?

Sve*_*ein 6

该命令.Platform返回平台的详细信息.您可以使用以下方式访问有关操作系统的信息

.Platform$OS.type
Run Code Online (Sandbox Code Playgroud)

这将返回"unix""windows".