Questions tagged [fread]

A binary-safe file read function in C/C++/PHP that returns the specified number of bytes from a stream. Also a fast csv parser in R's data.table package.

References:

1613 questions
19
votes
2 answers

What is a "byte" in C / C++

For example, here's a reference for fread: size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); Reads an array of count elements, each one with a size of "size bytes"... So how many BITS will read an fread(&x, 1, 1, stream)? Eight…
user389419
  • 243
  • 1
  • 2
  • 8
19
votes
2 answers

fread - skip lines starting with certain character - "#"

I am using the fread function in R for reading files to data.tables objects. However, when reading the file I'd like to skip lines that start with #, is that possible? I could not find any mention to that in the documentation.
Dnaiel
  • 7,622
  • 23
  • 67
  • 126
17
votes
2 answers

How to use fread and fwrite functions to read and write Binary files?

Hi in my project I've to read a .bin file which has sensor data in the form of short(16 bit values). I'm doing this using fread function into a buffer, but I feel that the reading-in is not happening correctly. I mean there is no consistence between…
user1190135
  • 215
  • 1
  • 2
  • 7
16
votes
1 answer

Using `fread` to import csv file from an archive into `R` without extracting to disk

I have a zip archive with several csv files in it. I would like to use fread to import selected csv files into R. With read.csv I can get the data as follows without extracting the archive. con <- unz("myarchive.zip", "file2.csv") file2 <-…
Crops
  • 5,024
  • 5
  • 38
  • 65
16
votes
4 answers

What is the equivalent of 'fread' from Matlab in Python?

I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right from the off with the checksum at the top of the…
Duncan Tait
  • 1,997
  • 4
  • 20
  • 24
16
votes
1 answer

How does fread know when the file is over in C?

So I'm not entirely sure how to use fread. I have a binary file in little-endian that I need to convert to big-endian, and I don't know how to read the file. Here is what I have so far: FILE *in_file=fopen(filename, "rb"); char…
user202925
  • 521
  • 2
  • 5
  • 16
15
votes
3 answers

Function fread not terminating string by \0

New to files in C, trying to read a file via fread Here's the content of the file: line1 how Code used: char c[6]; fread(c,1,5,f1) When outputting var 'c', the contents appear with a random character at the end (eg: line1*) Does fread not…
Akash
  • 4,956
  • 11
  • 42
  • 70
15
votes
1 answer

Could not find function 'fread' in R 3.4 while reading a big dataset

I have installed package "microbenchmark" and then run: library(microbenchmark). Now, I am trying to read a csv file, but getting the error: "fread" function not found. setwd("C:/Data Analytics/R Assignments") library(microbenchmark) data <-…
Ranjan Kumar
  • 151
  • 1
  • 1
  • 4
15
votes
2 answers

fread - read all columns as character

I'm trying to read a file into R using data.table / fread. Some of the fields have leading zeros and I just want to read the data in as characters and manually fix them. However I can't figure out how to convey this to fread. I'm trying this and…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
12
votes
2 answers

What is "short item count" in fread()?

When I was 'man fread', I got this: RETURN VALUE fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end- of-file is reached, the return…
zhanxw
  • 3,159
  • 3
  • 34
  • 32
12
votes
1 answer

Why does an fread loop require an extra Ctrl+D to signal EOF with glibc?

Normally, to indicate EOF to a program attached to standard input on a Linux terminal, I need to press Ctrl+D once if I just pressed Enter, or twice otherwise. I noticed that the patch command is different, though. With it, I need to press Ctrl+D…
12
votes
2 answers

How can I use fread to read gz files in R?

I am on a windows machine trying to speed up the read.table step. My files are all .gz. x=paste("gzip -c ",filename,sep="") phi_raw = fread(x) Error in fread(x) : Cannot understand the error . Its a bit too cryptic for me. Not a duplicate as…
pythOnometrist
  • 6,531
  • 6
  • 30
  • 50
11
votes
3 answers

Why does fread mess with my byte order?

Im trying to parse a bmp file with fread() and when I begin to parse, it reverses the order of my bytes. typedef struct{ short magic_number; int file_size; short reserved_bytes[2]; int data_offset; }BMPHeader; ... BMPHeader…
Chase Walden
  • 1,252
  • 1
  • 14
  • 31
11
votes
1 answer

R using fread colClasses or skip arguments to read csv with no column headers

I would like to be able to skip a column that is read into R via data.table's fread function in v1.8.9. But the csv I am reading in, has no column headers…which appears to be a problem for fread... is there a way to just specify that I don't want…
h.l.m
  • 13,015
  • 22
  • 82
  • 169
11
votes
1 answer

ifstream.eof() - end of file is reached before the real end

I have a roughly 11.1G binary file where stores a series of the depth frames from the Kinect. There are 19437 frames in this file. To read one frame per time, I use ifstream in fstream but it reaches eof before the real end of the file. (I only got…
willSapgreen
  • 1,365
  • 2
  • 17
  • 27