In python, one can get the path to the desktop on a Windows computer using:
os.sep.join((os.path.expanduser("~"), "Desktop"))
Is there something equivalent in R?
If we want to check the current directory of the R script, we can use getwd( ) function. For getwd( ), no need to pass any parameters. If we run this function we will get the current working directory or current path of the R script. To change the current working directory we need to use a function called setwd( ).
In the navigation pane on the left side, right-click Desktop and select Properties. In the Properties window, click the Location tab. The directory path to the desktop is displayed in the text field on the Location tab.
One of the great things about using RStudio Projects is that when you open a project it will automatically set your working directory to the appropriate location. You can check the file path of your working directory by looking at bar at the top of the Console pane.
The ~
expands to your documents home, rather than your user profile where the desktop is normally located. I recommend you use Sys.getenv
to find your user profile:
file.path(Sys.getenv("USERPROFILE"),"Desktop")
Something like (like mentioned in the comment) :
file.path(path.expand('~'),'Desktop')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With