R script call in Command Line

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

R script call in Command Line

Amitoj S. Chopra
I wrote a R script that will grep a file and parse it for me for a particular phrase. It will then save the file in a specific location.
Here is the R script:
con <- file("C:/test/VeriSeqNIPT_Method__Trace.trc")
open(con)
request_method = grep("Clean up instrument", file, value = T)
writeLines(request_method, con = "C:/test1/analysis-output.txt")
close(con)

I am trying to run this script from the command line to copy a few files as well. Here is the script I am running in command line. This script backup the trace file and then deleting the original

set source=C:\test
set destination=C:\BackUp
xcopy %source% %destination% /y
del C:\test%%
cd C:\Program Files\R\R-3.2.3\bin
Rscript C:\testscript.R

What is happening that the R script and cmd script (without calling the R script both work fine
When I run them all together like shown above, I get the error:
"Error in as.character(x): cannot coerce type 'closure' to vector of type 'character'
Calls:grep -> structure
Executed halted:

What is going on here?
Reply | Threaded
Open this post in threaded view
|

Re: R script call in Command Line

Amitoj S. Chopra
Found the error!
Here is the new script:


x="C:/Test/Absolut_Method_e0b6544aa8c64eb29c1e0857960ab363_Trace.trc"
con <- file(x)
open(con);
trace <- readLines(con)

request_method = grep("Clean up instrument", trace, value = T)
writeLines(request_method, con = "C:/test1/analysis-output.txt")