Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the desktop path in R

Tags:

path

r

desktop

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?

like image 255
John Waller Avatar asked Sep 17 '14 09:09

John Waller


People also ask

How do I find my path 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( ).

How do I find my desktop path?

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.

Where is the file path in RStudio?

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.


2 Answers

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")
like image 114
James Avatar answered Oct 07 '22 16:10

James


Something like (like mentioned in the comment) :

file.path(path.expand('~'),'Desktop')
like image 42
agstudy Avatar answered Oct 07 '22 16:10

agstudy