[R] Linux System Function

Ryan Garner ryan.steven.garner at gmail.com
Sat Apr 24 01:07:23 CEST 2010


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.



More information about the R-help mailing list