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
10
votes
2 answers

fread Only first 5 bytes of .PNG file

I've made a simple resource packer for packing the resources for my game into one file. Everything was going fine until I began writing the unpacker. I noticed the .txt file - 26 bytes - that I had packed, came out of the resource file fine, without…
Sam Blackburn
  • 288
  • 2
  • 9
10
votes
1 answer

Error in R data.table v1.9.6 - function "fread"

I recently updated to data.table 1.9.6 and get the following error when using fread: fread("Aug14.csv") Error in fread("Aug14.csv") : 4 arguments passed to .Internal(nchar) which requires 3 Another post discusses this error in another context,…
JK_chitown
  • 179
  • 3
  • 9
10
votes
0 answers

Read multiple gzip files into a single data.table using fread (and data connections)

I was looking at this thread: 'append multiple large data.table's; custom data coercion using colClasses and fread; named pipes' I see from "Matt Dowle", that fread "can accept non-files such as http addresses and connections". I tried passing a…
GMCB
  • 187
  • 2
  • 15
10
votes
11 answers

Buffered reading from stdin using fread in C

I am trying to efficiently read from the stdin by using setvbuf in `_IOFBF~ mode. I am new to buffering. I am looking for working examples. The input begins with two integers (n,k). The next n lines of input contain 1 integer. The aim is to print…
N 1.1
  • 12,418
  • 6
  • 43
  • 61
10
votes
1 answer

fread in R imports a large .csv file as a data frame with one row

I'm importing a large .csv file into R (about 0.5 million rows), so I've been trying to use fread() from the data.table package as a faster alternative to read.table() and read.csv(). However, fread() returns a data frame with all of the data from…
UCLAEeb
  • 103
  • 1
  • 1
  • 7
10
votes
3 answers

fread from data.table package when column names include spaces and special characters?

I have a csv file where column names include spaces and special characters. fread imports them with quotes - but how can I change this behaviour? One reason is that I have column names starting with a space and I don't know how to handle them. Any…
Rico
  • 1,998
  • 3
  • 24
  • 46
9
votes
2 answers

Is there a faster way than fread() to read big data?

Hi first of all I already search on stack and google and found posts such at this one : Quickly reading very large tables as dataframes. While those are helpfull and well answered, I'm looking for more informations. I am looking for the best way to…
Gainz
  • 1,721
  • 9
  • 24
9
votes
2 answers

R fread and strip white

I have a csv file with extra white spaces that I want to read into R as a dataframe, stripping the white spaces. This can be achieved by using testdata<-read.csv("file.csv", strip.white=TRUE) The problem is that the dataset large and takes about…
DaReal
  • 597
  • 3
  • 10
  • 24
9
votes
2 answers

How do I read an integer from a binary file using fread?

I've realized that my much bigger file is failing because it can't properly read the first integer in a binary file. This is my test file I've set up to do only that. I know that the int I'm reading will always be 1 byte so I read the data into a…
user3081405
  • 111
  • 1
  • 1
  • 2
9
votes
1 answer

Unexpected return value from fread()

#include #include #include int main() { FILE* bmp = NULL; uint32_t offset; uint8_t* temp = NULL; size_t read; unsigned int x_dim = 600, y_dim = 388; bmp = fopen("test_colour.bmp", "r"); …
simon
  • 1,125
  • 1
  • 10
  • 20
8
votes
3 answers

Go to a certain point of a binary file in C (using fseek) and then reading from that location (using fread)

I am wondering if this is the best way to go about solving my problem. I know the values for particular offsets of a binary file where the information I want is held...What I want to do is jump to the offsets and then read a certain amount of…
user1291631
  • 83
  • 1
  • 1
  • 4
8
votes
2 answers

clang-analyze: how to avoid "garbage value" warning?

When checking #include #include int main(void) { char c[20]; size_t l; l = fread(c, sizeof c, 1, stdin); if (l != 1) return 1; return c[0] == 42; } with clang, I get $ clang --analyze -Xclang…
ensc
  • 6,704
  • 14
  • 22
8
votes
2 answers

fread together with grepl

I have a data (large data 125000 rows, ~20 MB) in which some of the rows with certain string need to be deleted and some columns need to be selected during the reading process. Firstly, I discovered that grepl function does not work properly since…
Alexander
  • 4,527
  • 5
  • 51
  • 98
8
votes
1 answer

fread() a struct in c

For my assignment, I'm required to use fread/fwrite. I wrote #include #include struct rec{ int account; char name[100]; double balance; }; int main() { struct rec rec1; int c; FILE *fptr; fptr =…
user153882
  • 337
  • 1
  • 3
  • 15
8
votes
3 answers

How to read a binary file in c? (video, images, or text)

I am trying to copy a file from a specified library to the current directory. I can copy text files perfectly. Any other files become corrupt. The program detects a feof before it should. #include int BUFFER_SIZE = 1024; FILE…
Collin Price
  • 5,620
  • 3
  • 33
  • 35