How do I pass a filename as an argument to the system command to count the
number of records in that file? I only know how to do it by hardcoding it.

HARDCODING EXAMPLE
> test <- matrix(1:20,ncol=5)
> write(x = test,file = "test.txt")
> records <- as.numeric(system("cat test.txt | wc -l",intern = TRUE))
> records
[1] 4

??? NON-HARCODING EXAMPLE ???
> file = "test.txt"
> records <- as.numeric(system("cat file | wc -l",intern = TRUE))
cat: file: No such file or directory
> records <- as.numeric(system("cat" test.txt "| wc -l",intern = TRUE))
Error: unexpected symbol in "records <- as.numeric(system("cat" test.txt"

TFYH

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Linux-System-Function-tp2063058p2063058.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to