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?
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?
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')
Can't add a comment to James' answer, so here's another Answer.
On a terminal server network:
file.path(Sys.getenv("USERPROFILE"),"Desktop")
gives me the wrong result
file.path(Sys.getenv("HOMESHARE"),"Desktop")
gives me the right result
On my local machine it's the other way round. I haven't yet found a solution which works in both environments.
EDITED TO ADD
OK, this is a bit of a kludge based on the link I gave in my comment. A Windows expert could probably do it better, but I think this works in both environments and should be robust against changes in Desktop path.
Create a VBscript file to return the Desktop path: getDesk.vbs
dim WSHShell, desktop, pathstring, objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
Set WSHshell = CreateObject("WScript.Shell")
desktop = WSHShell.SpecialFolders("Desktop")
pathstring = objFSO.GetAbsolutePathName(desktop)
WScript.Echo pathstring
Now in R you can execute the VBscript to return the Desktop path
system("cscript //nologo getDesk.vbs", intern=TRUE)