syrvn
2012-Jun-14 10:14 UTC
[R] Open windows explorer with specific path using system command
Hello! I found out that it is possible to open the windows explorer with a predefined path via the cmd.exe program using the following command: explorer PATH Back in R using the following command opens up the windows explorer: system("explorer", intern=TRUE) However, when I specify a path R returns the following warning message and does not open the explorer at the specified path:> system("explorer C:\\Users\\xxx", intern=TRUE)character(0) attr(,"status") [1] 1 Warning message: running command 'explorer C:\Users\xxx' had status 1 I quoted the \ otherwise R complained about not recognising \U from \Users. However, when the command is executed as we would expect the double \\ are replaced by only one \. When I copy paste the explorer C:\Users\xxx bit from the R warning message into the cmd.exe program the explorer is opened up at the specified path. Does anybody have any idea why that fails? Many thanks Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Open-windows-explorer-with-specific-path-using-system-command-tp4633354.html Sent from the R help mailing list archive at Nabble.com.
peter dalgaard
2012-Jun-14 11:27 UTC
[R] Open windows explorer with specific path using system command
On Jun 14, 2012, at 12:14 , syrvn wrote:> Hello! > > I found out that it is possible to open the windows explorer with a > predefined path via the cmd.exe program using the following command: > > explorer PATH > > Back in R using the following command opens up the windows explorer: > > system("explorer", intern=TRUE) > > However, when I specify a path R returns the following warning message and > does not open the explorer at the specified path: > >> system("explorer C:\\Users\\xxx", intern=TRUE) > character(0) > attr(,"status") > [1] 1 > Warning message: > running command 'explorer C:\Users\xxx' had status 1 > > I quoted the \ otherwise R complained about not recognising \U from \Users. > > However, when the command is executed as we would expect the double \\ are > replaced by only one \. > > When I copy paste the explorer C:\Users\xxx bit from the R warning message > into the cmd.exe program the explorer is opened up at the specified path. > > Does anybody have any idea why that fails?Could it be taking the whole line as a command name (with an embedded space character)? You might need the shell() function rather than system(). -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com