简体   繁体   English

在 R 中获取 windows 系统文件夹(用户主目录、“我的文档”等)路径

[英]Get windows system folders (user home directory, "My documents", etc) path in R

I would like to get the full path of user's home folder (usually something like C:\Users\%USERNAME%) or "My documents" folder and can't find the way to do this from R script.我想获取用户主文件夹的完整路径(通常类似于 C:\Users\%USERNAME%)或“我的文档”文件夹,但无法从 R 脚本中找到执行此操作的方法。 Is there any solution for this?有什么解决办法吗?

我想你想要:

path.expand('~')

使用包fs ,您还可以获得主目录:

library(fs)

path_home()

To get C:/Users/%USERNAME% without any extra package (or, with "base") you can use要获得 C:/Users/%USERNAME% 没有任何额外的 package (或者,使用“base”),您可以使用

Sys.getenv("USERPROFILE")

The path.expand('~') suggested above gave me the equivalent of C:/Users/%USERNAME%/Documents上面建议的path.expand('~')给了我相当于 C:/Users/%USERNAME%/Documents

obs: that worked for me in Win 10 and Win11 and with R3.4 and 4.1 obs:在 Win 10 和 Win11 以及 R3.4 和 4.1 中对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM