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.

527 questions
39
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
  • 491
  • 1
  • 4
  • 3
38
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
  • 53,471
  • 32
  • 129
  • 174
28
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
  • 2,093
  • 4
  • 16
  • 20
22
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
  • 325
  • 4
  • 14
18
votes
3 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
  • 459
  • 5
  • 9
16
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,395
  • 2
  • 13
  • 32
14
votes
2 answers

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
  • 1,016
  • 6
  • 15
13
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
  • 2,936
  • 5
  • 29
  • 44
13
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,536
  • 2
  • 20
  • 38
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
  • 3,136
  • 2
  • 24
  • 36
11
votes
3 answers

Setting row names on a tibble is deprecated. Error: invalid 'row.names' length

I am trying to make a heatmap of a sites vs. species abundances matrix. With thanks to Maurits Evers for some of this code, I am still not able to run it without the error message: Setting row names on a tibble is deprecated.Error in …
chloep
  • 139
  • 1
  • 2
  • 10
11
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,898
  • 20
  • 36
9
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
  • 3,222
  • 4
  • 28
  • 35
9
votes
2 answers

Markdown table to data frame in R

There are numerous ways to convert a data frame into a Markdown table. But how does one convert back to a dataframe, given a Markdown table Given a table of a form: Table Header | Second Header ------------- | ------------- Table Cell | Cell 2 Cell…
Taraas
  • 1,268
  • 1
  • 11
  • 20
8
votes
1 answer

Why does my code using read_fwf() not work like in the book?

I study R with R Cookbook 2nd edition. in 4.6 Reading Fixed-Width Records, I typed code as written in book. but my code doesn't work like book Fisher R.A. 1890 1962 Pearson Karl 1857 1936 Cox Gertrude 1900 1978 Yates Frank …
1
2 3
35 36