Reputation: 8646
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. Is there any solution for this?
Upvotes: 18
Views: 7391
Reputation: 53
To get C:/Users/%USERNAME% without any extra package (or, with "base") you can use
Sys.getenv("USERPROFILE")
The path.expand('~')
suggested above gave me the equivalent of C:/Users/%USERNAME%/Documents
obs: that worked for me in Win 10 and Win11 and with R3.4 and 4.1
Upvotes: 4
Reputation: 255
With the package fs
, you can also get the home directory:
library(fs)
path_home()
Upvotes: 3