Sunday, 8 September 2013

Passing a predefined filename argument to awk via system() in R

Passing a predefined filename argument to awk via system() in R

I am struggling with something small but important with syntax, trying to
pass a pre-defined path and filename to awk within the system() call in R
(OSX, R3.0.1; readLines() and scan() can NOT accomplish what I need).
The use of system and the file name, directly within R, works fine
system("awk 'NR==2' ~/path/filename", intern=TRUE)
However
filename<-"~/path/filename"
system("awk 'NR==2' filename", intern=TRUE)
returns the frustrating error
character(0)
attr(,"status")
[1] 2
Warning message:
running command 'awk 'NR==2' filename' had status 2
awk: can't open file filename
source line number 1
I expect I need to escape something somewhere in the filename, but I don't
know where, or how.

No comments:

Post a Comment