fread

Error in R data.table v1.9.6 - function “fread”

心已入冬 提交于 2019-11-28 07:18:03
问题 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, but this worked fine prior to upgrading to data.table 1.9.6. Any advice? Here's my set up: sessionInfo() R version 3.2.0 (2015-04-16) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC

Read files separated by tab in c

假如想象 提交于 2019-11-28 05:36:39
问题 I am really new to C, and the reading files thing drives me crazy... I want read a file including name, born place and phone number, etc. All separated by tab The format might be like this: Bob Jason Los Angeles 33333333 Alice Wong Washington DC 111-333-222 So I create a struct to record it. typedef struct Person{ char name[20]; char address[30]; char phone[20]; } Person; I tried many ways to read this file into struct but it failed. I tired fread: read_file = fopen("read.txt", "r"); Person

Parse/Read Bitmap file in C

僤鯓⒐⒋嵵緔 提交于 2019-11-28 01:58:55
问题 I'm trying to make a program to read data from a bitmap file (.bmp, Windows file format, 8bit). Right now I'm stuck on reading the headers before the image data. I used the specifications for bmp that I found here to make these structs to hold the file header, info header, and image data of the bmp: typedef struct { unsigned char fileMarker1; unsigned char fileMarker2; unsigned int bfSize; uint16_t unused1; uint16_t unused2; unsigned int imageDataOffset; } FILEHEADER; typedef struct {

Function fread not terminating string by \0

心不动则不痛 提交于 2019-11-28 00:13:50
问题 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 terminate the string or am I missing something? 回答1: No. The fread function simply reads a number of elements, it has no notion of "strings". You can add the NUL terminator yourself You can use fgets / fscanf instead Personally I would go with fgets . 回答2:

Reason behind speed of fread in data.table package in R

此生再无相见时 提交于 2019-11-27 14:37:17
问题 I am amazed by the speed of the fread function in data.table on large data files but how does it manages to read so fast? What are the basic implementation differences between fread and read.csv ? 回答1: I assume we are comparing to read.csv with all known advice applied such as setting colClasses , nrows etc. read.csv(filename) without any other arguments is slow mainly because it first reads everything into memory as if it were character and then attempts to coerce that to integer or numeric

Does fread move the file pointer?

自古美人都是妖i 提交于 2019-11-27 11:19:24
问题 Simple question, When i use fread: fread(ArrayA, sizeof(Reg), sizeBlock, fp); My file pointer, fp is moved ahead? 回答1: Answer: Yes, the position of the file pointer is updated automatically after the read operation, so that successive fread() functions read successive file records. Clarification: fread() is a block oriented function. The standard prototype is: size_t fread(void *ptr, size_t size, size_t limit, FILE *stream); The function reads from the stream pointed to by stream and places

Reading in chunks at a time using fread in package data.table

早过忘川 提交于 2019-11-27 11:12:30
问题 I'm trying to input a large tab-delimited file (around 2GB) using the fread function in package data.table . However, because it's so large, it doesn't fit completely in memory. I tried to input it in chunks by using the skip and nrow arguments such as: chunk.size = 1e6 done = FALSE chunk = 1 while(!done) { temp = fread("myfile.txt",skip=(chunk-1)*chunk.size,nrow=chunk.size-1) #do something to temp chunk = chunk + 1 if(nrow(temp)<2) done = TRUE } In the case above, I'm reading in 1 million

using colClasses in fread

我们两清 提交于 2019-11-27 10:31:44
问题 I don't know how to choose specific columns using the colClasses option in fread . I tried to use NULL in several ways but nothing worked. Here's a minimal example. I just want columns 1 and 3. dt <- data.table(a=1:5,b=6:10,c=10:14) write.csv(dt,"dt.csv",row.names=F) dt <- fread("dt.csv",colClasses=?) packageVersion("data.table") [1] ‘1.8.10’ getRversion() [1] ‘3.0.1’ The imported dataset should look like this: a c 1: 1 10 2: 2 11 3: 3 12 4: 4 13 5: 5 14 回答1: UPDATE: This is now implemented

PHP - Returning the last line in a file?

六眼飞鱼酱① 提交于 2019-11-27 05:02:18
I'm guessing it's fgets, but I can't find the specific syntax. I'm trying to read out (in a string I'm thinking is easier) the last line added to a log file. The simplest naive solution is simply: $file = "/path/to/file"; $data = file($file); $line = $data[count($data)-1]; Though, this WILL load the whole file into memory. Possibly a problem (or not). A better solution is this: $file = escapeshellarg($file); // for the security concious (should be everyone!) $line = `tail -n 1 $file`; Tomalak This looks like it is what you are looking for: tekkie.flashbit.net: Tail functionality in PHP It

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

天大地大妈咪最大 提交于 2019-11-27 04:31:43
问题 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 <stdio.h> int BUFFER_SIZE = 1024; FILE *source; FILE *destination; int n; int count = 0; int written = 0; int main() { unsigned char buffer[BUFFER_SIZE]; source = fopen("./library/rfc1350.txt", "r"); if (source) { destination = fopen("rfc1350.txt", "w"); while (!feof(source)) { n = fread(buffer, 1,