1) count.fields Not sure if count.fields
reads the whole file into R at once. Try it to see if it works.
length(count.fields("myfile.csv", sep = ","))
If the file has a header subtract one from the above.
2) sqldf Another possibility is:
library(sqldf)
read.csv.sql("myfile.csv", sep = ",", sql = "select count(*) from file")
You may need other arguments as well depending on header, etc. Note that this does not read the file into R at all -- only into sqlite.
3) wc Use the system command wc which should be available on all platforms that R runs on.
shell("wc -l myfile.csv", intern = TRUE)
or to directly get the number of lines in the file
read.table(pipe("wc -l myfile.csv"))[[1]]
or
read.table(text = shell("wc -l myfile.csv", intern = TRUE))[[1]]
Again, if there is a header subtract one.
If you are on Windows be sure that Rtools is installed and use this:
read.table(pipe("C:\\Rtools\\bin\\wc -l myfile.csv"))[[1]]
Alternately on Windows without Rtools try this:
read.table(pipe('find /v /c "" myfile.csv'))[[3]]
See How to count no of lines in text file and store the value into a variable using batch script?