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
5
votes
1 answer

Dealing with Byte Order Mark (BOM) in R

Sometimes a Byte Order Mark (BOM) is present at the beginning of a .CSV file. The symbol is not visible when you open the file using Notepad or Excel, however, When you read the file in R using various methods, you will different symbols in the name…
Gaurav Singhal
  • 998
  • 2
  • 10
  • 25
5
votes
1 answer

readr::read_csv("file.csv", col_types = rep("c", times = 18)) gives Error: not compatible with STRSXP

I'm trying to read in a fairly simple csv file, but readr is throwing an error when I try to specify the column types. Here's a small snippet of my data: text <-…
tblznbits
  • 6,602
  • 6
  • 36
  • 66
4
votes
1 answer

Specify a column type across multiple columns with tidy-selection in readr package

I attempt to use read_csv from {readr} to read a CSV file into R. To demonstrate my real issue, I reset the argument guess_max to 5 at first (default is 1000) library(readr) formals(read_csv)$guess_max <- 5 and take a smaller literal data for…
user18894435
  • 373
  • 1
  • 10
4
votes
5 answers

Read all csv files in a directory and add the name of each file in a new column

I have this code that reads all CSV files in a directory. nm <- list.files() df <- do.call(rbind, lapply(nm, function(x) read_delim(x,';',col_names = T))) I want to modify it in a way that appends the filename to the data. The result would be a…
GitZine
  • 445
  • 3
  • 14
4
votes
3 answers

How to read csv file with column containing unqouted newlines?

library(tidyverse) I have this stupid csv file where someone forgot to quote the string in the last column which may contain newlines. (The 2nd row in this example doesn’t) csv_file <- str_c( "a,b,c\n", "1,1,first\nrow\n", "1,1,second…
Peter H.
  • 1,995
  • 8
  • 26
4
votes
1 answer

Why is the parse_number function saying my character vector is not a character?

I'm using R to pull out numbers from strings of ids. In the past, I've used readr's parse_number() function, but recently, I'm getting a bizarre error where it's saying that my character column is not character: library(dplyr) library(readr) test…
J.Sabree
  • 2,280
  • 19
  • 48
4
votes
1 answer

Extract column from text in memory

I'm looking for a fast way to read in a single column from tab-separated text that lives as a character vector in memory. I'm using a file format specific to my field that roughly resembles a compressed tsv file. It is fast and easy to read in a…
teunbrand
  • 33,645
  • 4
  • 37
  • 63
4
votes
1 answer

Make readxl::read_excel rename only the second duplicate column in R

In readr, the read_csv command handles duplicate column names by renaming the second duplicate and leaves the first unaltered. See the following example, taken from https://github.com/tidyverse/readxl/issues/53. readr::read_csv("x,x,y\n1,2,3\n") #>…
Rob Creel
  • 323
  • 1
  • 8
4
votes
1 answer

How to enforce readr to consider correct decimal/grouping mark?

Having csv-files with the European number format style (1234.56 -> 1.234,56) should be handeled by a readr function or fread(). Even though read_csv2() should be exactly designed for this task, it basically ignores the specification. It only…
mnist
  • 6,571
  • 1
  • 18
  • 41
4
votes
1 answer

How to split and make new csv files based on date/day in r?

Hi I have an 8GB file which I need to do some analysis. However my RAM is not that great. To efficiently work, I decided to split my csv file based on rows with following code: library(tidyverse) sample_df <- readr::read_csv("sample.csv") #Read in…
CaseebRamos
  • 684
  • 3
  • 18
4
votes
1 answer

Getting Error "Error: Unknown TZ UTC" After Remote Desktop RStudio Update

Running RStudio 1.2.5033, R 3.6.1, and readr 1.3.1. Previously was having no issues reading in a CSV file yesterday, software was updated to what you see above and now getting Error: Unknown TZ UTC when I try to read in anything with table.df <-…
JBP
  • 83
  • 9
4
votes
2 answers

Using mutate_at with mutate_if

I'm in the process of creating a generic function in my package. The goal is to find columns that are percent columns, and then to use parse_number on them if they are character columns. I haven't been able to figure out a solution using mutate_at…
Jazzmatazz
  • 615
  • 7
  • 18
4
votes
1 answer

Read columns with readr using regular expressions

I need to import data files with various column numbers. Finally, the code should be used by other co-workers being not very familiar with R. So it should be robust and without warning messages preferably. The main problem is that the headder is…
Pelle
  • 257
  • 2
  • 8
4
votes
2 answers

Read CSV in R and filter columns by name

Let's say I have a CSV with dozens or hundreds of columns and I want to pull in just about 2 or 3 columns. I know about the colClasses solution as described here but the code gets very unreadable. I want something like usecols from pandas'…
gsmafra
  • 2,434
  • 18
  • 26
4
votes
2 answers

Remove attributes from data read in readr::read_csv

readr::read_csv adds attributes that don't get updated when the data is edited. For example, library('tidyverse') df <- read_csv("A,B,C\na,1,x\nb,1,y\nc,1,z") # Remove columns with only one distinct entry no_info <- df %>%…
conor
  • 1,204
  • 1
  • 18
  • 22
1 2
3
35 36