Wiener, Matthew
2003-Sep-12 02:12 UTC
[R] Getting 2 kinds of quotes inside a pasted string
Hi, all.
I would like to use "pipe" to run a file through an awk program before
scanning (to reduce the amount of data I'll be taking in). I would like to
construct the awk program in R, and also to be able to set the awk variable
FS, to accommodate different field separators in different files.
My problem is that I keep getting the quotes escaped in the string that
comes out, and that sets the field separator to something different.
What I'd like to end up with is something like:
awk 'BEGIN{FS=";"}'
If I can get this, I can put the rest of the awk program together. What I
actually keep getting is
awk 'BEGIN{FS=\";\"}'.
That is, the quote characters are escaped.
I can print this with quote = FALSE, and get the string I'm looking for.
But when I paste that into the larger awk program, the quotes are
nonetheless escaped (presumably because the print, quote = FALSE affects
only display and not the internal structure).
I've also tried sprintf, but run into the same problem. I'd very much
appreciate it if someone could show me how to create the string I'm looking
for, or tell me a better way to go about filtering the file in the first
place. I'd prefer not to scan in everything and do the subsetting in R; the
files I'm using are very large, and the whole point is not to have to load
the whole file into memory.
Thanks very much,
Matthew Wiener
RY84-202
Applied Computer Science & Mathematics Dept.
Merck Research Labs
126 E. Lincoln Ave.
Rahway, NJ 07065
732-594-5303
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments,...{{dropped}}
Dirk Eddelbuettel
2003-Sep-12 02:37 UTC
[R] Getting 2 kinds of quotes inside a pasted string
On Thu, Sep 11, 2003 at 10:12:56PM -0400, Wiener, Matthew wrote:> My problem is that I keep getting the quotes escaped in the string that > comes out, and that sets the field separator to something different. > > What I'd like to end up with is something like: > awk 'BEGIN{FS=";"}' > If I can get this, I can put the rest of the awk program together. What I > actually keep getting is > awk 'BEGIN{FS=\";\"}'. > That is, the quote characters are escaped.This prints what you want: > print("awk \'BEGIN\{FS=\";\"\}\'") [1] "awk 'BEGIN{FS=\";\"}'" and I can pipe it into tee(1) which logs to its first argument: > con<-pipe("tee /tmp/matt.log","w") > cat("awk \'BEGIN\{FS=\";\"\}\'\n", file=con) > awk 'BEGIN{FS=";"}' # this line echoes by tee # pressed RETURN > close(con) and it all looks fine: edd at chibud:~> cat /tmp/matt.log awk 'BEGIN{FS=";"}' edd at chibud:~> Hth, Dirk -- Those are my principles, and if you don't like them... well, I have others. -- Groucho Marx