Questions tagged [readr]

readr is an R package that provides a fast and friendly way to read tabular data.

An R package written by Hadley Wickham. The goal of readr is to provide a fast and friendly way to read tabular data into R.

373 questions
33
votes
5 answers

How do you read multiple .txt files into R?

I'm using R to visualize some data all of which is in .txt format. There are a few hundred files in a directory and I want to load it all into one table, in one shot. Any help? EDIT: Listing the files is not a problem. But I am having trouble going…
Eric Brotto
  • 49,233
  • 29
  • 122
  • 171
27
votes
6 answers

How to import a .tsv file

I need to read a table that is a .tsv file in R. test <- read.table(file='drug_info.tsv') # Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : # line 1 did not have 10 elements test <- read.table(file='drug_info.tsv',…
Andrew Voronkov
  • 371
  • 1
  • 3
  • 3
23
votes
2 answers

how to skip reading certain columns in readr

I have a simple csv file called "test.csv" with the following content: colA,colB,colC 1,"x",12 2,"y",34 3,"z",56 Let's say I want to skip reading in colA and just read in colB and colC. I want a general way to do this because I have lots of files…
vergilcw
  • 1,963
  • 4
  • 13
  • 20
18
votes
4 answers

How can I write dplyr groups to separate files?

I'm trying to create separate .csv files for each group in a data frame grouped with dplyr's group_by function. So far I have something like by_cyl <- group_by(mtcars, cyl) do(by_cyl, write_csv(., "test.csv")) As expected, this writes a single…
Nat
  • 285
  • 3
  • 14
13
votes
1 answer

base R faster than readr for reading multiple CSV files

There is a lot of documentation on how to read multiple CSVs and bind them into one data frame. I have 5000+ CSV files I need to read in and bind into one data structure. In particular I've followed the discussion here: Issue in Loading multiple…
Lloyd Christmas
  • 966
  • 4
  • 13
12
votes
1 answer

read_csv() parsing error message, how to interpret?

I am in the middle of parsing in a large amount of csv data. The data is rather "dirty" in that I have inconsistent delimiters, spurious characters and format issues that cause problems for read_csv(). My problem here, however, is not the dirtiness…
Angelo
  • 3,445
  • 3
  • 25
  • 39
12
votes
2 answers

Suppress reader parse problems in r

I am currently reading in a file using the package readr. The idea is to use read_delim to read in row for row to find the maximum columns in my unstructured data file. The code outputs that there are parsing problems. I know of these and will deal…
Hanjo Odendaal
  • 1,175
  • 1
  • 11
  • 25
12
votes
2 answers

Why does dplyr's mutate() change the time format?

I use readr to read in data which consists a date column in time format. I can read it in correctly using the col_types option of readr. library(dplyr) library(readr) sample <- "time,id 2015-03-05 02:28:11,1674 2015-03-03 13:10:59,36749 2015-03-05…
janosdivenyi
  • 2,854
  • 2
  • 20
  • 35
10
votes
4 answers

Is it possible to write stdout using write_csv() from readr?

I'm using bash to pipe data through an Rscript like so: cat random.csv | Rscript test.R arg >| delete.csv My aim is to use the R package readr to both read stdin and write stdout. I found the answer to stdin…
Luke Singham
  • 1,194
  • 2
  • 14
  • 32
9
votes
2 answers

Suppress All Messages/Warnings with Readr read_csv function

I am creating a rmarkdown pdf report. I used read_csv function from readr package to import some csv files in a folder. I used SuppressMessages/Warnings functions to hide all warnings/messages, but I still get the messages as below when trying to…
Felix Zhao
  • 349
  • 3
  • 8
9
votes
2 answers

Reading csv files in chunks with `readr::read_csv_chunked()`

I want to read larger csv files but run into memory problems. Thus, I would like to try reading them in chunks with read_csv_chunked() from the readr package. My problem is that I do not really understand the callback argument. This is a minimal…
der_grund
  • 1,499
  • 13
  • 29
8
votes
2 answers

Could not find function "OlsonNames" when using read_csv with readr package

I am trying to read a csv file using read_csv() of R. library(readr) data <- read_csv("data/tmp.csv") tmp.csv is given below. "A", "B", "C", "D", "E", "F", "G", "H",…
qmaruf
  • 2,463
  • 2
  • 27
  • 48
7
votes
1 answer

What are the file formats that read into R the fastest?

It seems most intuitive that .rdata files might be the fasted file format for R to load, but when scanning some of the stack posts it seems that more attention has been on enhancing load times for .csv or other formats. Is there a definitive answer?
6
votes
1 answer

Create a col_types string specification for read_csv based on existing dataframe

I have a data.frame or tibble that, in one script, is written to a CSV file. In another script, that same CSV file is read into a data.frame or tibble. Using read_csv(), with the col_types= parameter, I can specify the column types to read in. …
mpettis
  • 2,468
  • 4
  • 19
  • 29
6
votes
2 answers

r, write_csv is changing all times/dates to UTC

I have found a very annoying problem that I want to share with the community. This is a question that I have found an acceptable solution for (detailed below), but I now have several follow-up questions. My knowledge of time stamps and POSIX…
Phil_T
  • 733
  • 6
  • 21
1
2 3
24 25