siddu479
2012-Oct-27 11:41 UTC
[R] Getting error while running unix commands within R using system() function
Hello All,
I use Cygwin ( unix on windows) heavily for all my text data processing.
Also use Cygwin inbuilt *R* to do numerical processing.
*My aim is to integrate R and unix commands to avoid heavy memory usage that
R takes normally.*
I can run many unix commands using system("some unix command or sh
script.sh
or even R file itself ") inside R.
But, When I tried to run the command *awk '{print "Hello"$1}'
infile.txt* to
prefix "Hello" to my first column of file infile.txt, like below in *R
*
*system(" awk '{print "Hello"$1}' infile.txt") *, I
am getting the below
error,
*Error: unexpected symbol in "system("awk '{print
"Hello"*
I tried even like *system('awk '{print "Hello"$1}'
infile.txt')*, but still
the same error.
This particular error is hampering my entire work, other wise I found this
is excellent way processing the text files at the same time reading back and
forth file outputs from R to unix and vice versa.
Can some one give me provide some solution to this problem ??
-----
Sidda
Business Analyst Lead
Applied Materials Inc.
--
View this message in context:
http://r.789695.n4.nabble.com/Getting-error-while-running-unix-commands-within-R-using-system-function-tp4647656.html
Sent from the R help mailing list archive at Nabble.com.
William Dunlap
2012-Oct-27 20:17 UTC
[R] Getting error while running unix commands within R using system() function
To diagnose a problem in R it pays to pull apart your expression
into a sequence of simpler ones. E.g., replace your expression
system(" awk '{print "Hello"$1}' infile.txt")
with the sequence
sysCmd <- " awk '{print "Hello"$1}' infile.txt"
system(sysCmd)
and you will see an error when running the first one, showing that
this has nothing to do with the system() function:
> sysCmd <- " awk '{print "Hello"$1}'
infile.txt"
Error: unexpected symbol in "sysCmd <- " awk '{print
"Hello"
Note where the error message ends, at a double quote, suggesting
that quoting may be the problem.
To put a double quote inside a double-quoted string you must
put a backslash in front of it
> sysCmd <- " awk '{print \"Hello\"$1}'
infile.txt"
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at
r-project.org] On Behalf
> Of siddu479
> Sent: Saturday, October 27, 2012 4:42 AM
> To: r-help at r-project.org
> Subject: [R] Getting error while running unix commands within R using
system() function
>
> Hello All,
>
> I use Cygwin ( unix on windows) heavily for all my text data processing.
> Also use Cygwin inbuilt *R* to do numerical processing.
> *My aim is to integrate R and unix commands to avoid heavy memory usage
that
> R takes normally.*
>
> I can run many unix commands using system("some unix command or sh
script.sh
> or even R file itself ") inside R.
>
> But, When I tried to run the command *awk '{print
"Hello"$1}' infile.txt* to
> prefix "Hello" to my first column of file infile.txt, like below
in *R *
> *system(" awk '{print "Hello"$1}' infile.txt")
*, I am getting the below
> error,
> *Error: unexpected symbol in "system("awk '{print
"Hello"*
> I tried even like *system('awk '{print "Hello"$1}'
infile.txt')*, but still
> the same error.
>
> This particular error is hampering my entire work, other wise I found this
> is excellent way processing the text files at the same time reading back
and
> forth file outputs from R to unix and vice versa.
>
> Can some one give me provide some solution to this problem ??
>
>
>
>
>
>
>
>
> -----
> Sidda
> Business Analyst Lead
> Applied Materials Inc.
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Getting-error-while-
> running-unix-commands-within-R-using-system-function-tp4647656.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
siddu479
2012-Oct-28 03:03 UTC
[R] Getting error while running unix commands within R using system() function
Thanks William,
This solved my problem very well. Look like I asked a very trivial
question.
-----
Sidda
Business Analyst Lead
Applied Materials Inc.
--
View this message in context:
http://r.789695.n4.nabble.com/Getting-error-while-running-unix-commands-within-R-using-system-function-tp4647656p4647676.html
Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- listing the files in a directory using regular expressions
- transforming a .csv file column names as per a particular column rows using R code
- Excluding all teh columns from a data frame if the standard deviation of that column is zero(0).
- Syncronize Monitored Calls
- [PATCH] febootstrap-supermin-helper: Replace objcopy call for embedding init binary