You'll probably need to run it as (assuming PowerShell is in your path):
system("powershell -command \"gci -r|sort Length -desc|select fullname -f 5\"")
or, if you're not keen on escaping "
with \"
.
system('powershell -command "gci -r|sort Length -desc|select fullname -f 5"')
I'm also assuming that's how R escapes and embeds quotes in strings (from my cursory googling about string handling in R).
If you wish to capture the output to a variable (specifically, a character vector) you need to use the intern = TRUE
argument:
res <- system('powershell -command "gci -r|sort Length -desc|select fullname -f 5"', intern=TRUE)
For more information see:
http://stat.ethz.ch/R-manual/R-patched/library/base/html/system.html
In particular:
If intern = TRUE
, a character vector giving the output of the command, one line per character string.
and
If intern = FALSE
, the return value is an error code (0 for success),