-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: could read_lines() accept negative n_max, to read from end of file #983
Comments
While interesting, I don't think this is likely to be implemented. I would suggest you use |
the idea is that you don't bring the lines into memory. it would be crucial
if the file has a billion lines.
dan
…On Fri, Apr 3, 2020 at 2:49 PM Jim Hester ***@***.***> wrote:
While interesting, I don't think this is likely to be implemented. I would
suggest you use tail(n = N, vroom::vroom_lines('fname.txt'))
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#983 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD32VFWHKWAW2LGFUBLYYA3RKYOUFANCNFSM4HCJG6TQ>
.
|
Possible workaround: To get the number of lines in a file without reading all its contents into memory in R, you can use the count.fields() function. This function counts the number of fields (columns) in each line of a file and returns a vector with the count for each line. By taking the length of this vector, you can determine the number of lines in the file. Here's an example of how to use count.fields() to get the number of lines in a file:
Please note that count.fields() may read the file partially, but it does not load the entire file into memory. It only reads enough of the file to determine the number of fields in each line. https://stackoverflow.com/questions/39691133/counting-rows-with-fread-without-reading-the-whole-file |
I would like to do:
to read just the last line (since n_max=-1 currently reads the entire file). or
to read the last N-1 lines in the file. this way i don't have to know how many lines there are, skip them, etc.
The text was updated successfully, but these errors were encountered: