2013-03-12 31 views
0

我想在R中使用系统运行head <(cat file.txt),但转义<是个问题。转义R中的登录粘贴/系统命令小于

system(paste("head <(cat file.txt)")) 
sh: -c: line 0: syntax error near unexpected token `(' 
sh: -c: line 0: `head <(cat file.txt)' 

I've tried escaping it, but its not working 

system(paste("head /<(cat file.txt)")) 
head: cannot open `/<(cat file.txt)' for reading: No such file or directory 

有人可以提出一种替代方案。

干杯

+2

对于这样的问题,提供你所使用的系统是非常重要的。 – juba 2013-03-12 15:32:54

+0

@juba它的CentOS 5.8 – 2013-03-12 20:50:31

回答

6

的问题不逃避<。默认情况下,system运行与/bin/sh的命令,你的命令是不正确使用此外壳:

$ sh -c "head <(cat foo.txt)" 
sh: 1: Syntax error: "(" unexpected 

但它使用bash的作品。

在R,你可以尝试这样的:

system("bash -c 'head <(cat file.txt)'") 
+1

'shQuote'命令在这方面也可能有用。 – 2013-03-12 15:52:24