Any way to force fread() of data.table not to stop on empty lines?
Version 1.9.8 of data.table, released 25-NOV-2016, has a new blank.lines.skip
option to skip blank lines.
text <- "1,a\n\n2,b\n3,c\n4,a\n\n5,b\n\n6,c"
library(data.table)
fread(text)
## V1 V2
## 1: 2 b
## 2: 3 c
## 3: 4 a
## Warning message:
## In fread("1,a\n\n2,b\n3,c\n4,a\n\n5,b\n\n6,c") :
## Stopped reading at empty line 6 but text exists afterwards (discarded): 5,b
fread(text, blank.lines.skip=TRUE)
## V1 V2
## 1: 1 a
## 2: 2 b
## 3: 3 c
## 4: 4 a
## 5: 5 b
## 6: 6 c
R: Is there a way to fread data.table from file where some (irregular) lines are skipped?
Thanks to Frank,
Solution:
Step 1: Make lines that should be skipped blank (with external editor), then
Step 2: Run fread(text, blank.lines.skip=TRUE)
In R: Send a modified windows command to fread()
Assuming you already have the value stored in newestFile you can use paste0
to construct your string
fread_cmd <- paste0('findstr "." ', newestFile)
fread(fread_cmd, skip = 0, sep = "\n", header = FALSE)
How to stop fread from displaying messages when it is inside trycatch
I tried it, and with data.table
1.9.4 I got:
The system cannot find the path specified.
(Which I guess is the executive summary of your long German sentence ;) )
With data.table
version 1.9.6 it works as expected. So just update your packages:
update.packages()
And you should be fine.
Related Topics
Lapply to Add Columns to Each Dataframe in a List
Reading Big Data with Fixed Width
Deleting Every N-Th Row in a Dataframe
How to Find Difference Between Values in Two Rows in an R Dataframe Using Dplyr
Filter a Vector of Strings Based on String Matching
R: What's the How to Overwrite a Function from a Package
Adding Prefix or Suffix to Most Data.Frame Variable Names in Piped R Workflow
How to Use a Graphic Imported with Grimport as Axis Tick Labels in Ggplot2 (Using Grid Functions)
The Perils of Aligning Plots in Ggplot
Stop Lapply from Printing to Console
Get the Size of the Window in Shiny
Source Script to Separate Environment in R, Not the Global Environment
Reading a CSV File Organized Horizontally
R 3.3.0 Installing a Package on Windows: Gcc Not Found Error