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

In readr()/read_csv, how to import data with all columns as character

In readr()/read_csv, how to import data with all columns as character? Thanks! library(tidyverse) read_csv(readr_example("mtcars.csv")))
anderwyang
  • 1,801
  • 4
  • 18
3
votes
0 answers

Mixed Character Encodings in R: When a space isn't a space

These two strings are part of .csv files. They certainly look the same, but they are not. This causes all sorts of problems trying to use dplyr functions like left_join, filter or even base functions like merge. Since they render in the same…
Jeff Parker
  • 1,809
  • 1
  • 18
  • 28
3
votes
5 answers

Dealing with character variables containing semicolons in CSV files

I have a file separated by semicolons in which one of the variables of type character contains semicolon inside it. The readr::read_csv2 function splits the contents of those variables that have semicolons into more columns, messing up the…
Igor
  • 145
  • 8
3
votes
1 answer

Strange behaviour with parse_time()

I am trying to parse a string representing a period consisting of minutes, seconds, and milliseconds. My preferred functions for this would come from the readr package, where seconds and milliseconds may be seen jointly as partial seconds.…
3
votes
1 answer

pass text as specified columns to open as [type] using read_csv from readr in R

I have some .csv files which I would like to open, specifying the default column type as "i" for integer. However, certain files also have specific column which I would like to tell readr::read_csv to open with defined types (the logic of which…
Robert Hickman
  • 869
  • 1
  • 6
  • 22
3
votes
1 answer

Using vroom to read in Date column and all other columns as double in R

I have csv files with over 10000 variables in them. I want to use vroom to read them in, and want to identify column 1 as a date, column 2 as character, columns 3 and 4 as integer, and all the rest of the columns as double. How do I do this? My…
user8229029
  • 883
  • 9
  • 21
3
votes
1 answer

Reading files with double double quotes in R

I am reading a few thousand csv files where some columns have a very 'interesting' format: {""Q0"":""double double quote""} It seems read.csv reads it fine, but both read_csv and fread are doing different things (see below). My expectation would be…
Gorka
  • 3,555
  • 1
  • 31
  • 37
3
votes
3 answers

R, stringr, mutate (I think) - multiple partial string replacements in multiple strings

I am new to text mining, R and the tidy approach and am looking for kind advice to overcome a hurdle with pre-processing text strings read in from pdf files. The specific problem is with a multiple string replacement over multiple strings. I have…
3
votes
1 answer

Exporting to csv while preserving digits for integers expressed in ".0" in R

I have the following dataframe: myd <- data.frame(a = c(3.0, "2.0 (1.8, 2.2)")) myd$a[1] <- format(round(as.numeric(myd$a[1]), 1), nsmall = 1) My data looks like below: myd a 1 3.0 2 2.0 (1.8, 2.2) I want to export myd to…
Patrick
  • 1,057
  • 9
  • 23
3
votes
1 answer

R: parse_number fails if the string contains a dot

parse_number from readr fails if the character string contains a . It works well with special characters. library(readr) #works parse_number("%ç*%&23") #does not work parse_number("art. 23") Warning: 1 parsing failure. row col expected actual 1…
captcoma
  • 1,768
  • 13
  • 29
3
votes
1 answer

How do you set encoding/fileEncoding option in readr/tidyverse?

i have a textfile of an old spectrometer. It is encoded in "UTF-16LE" (I found this out with the readr:guess_encoding() function). I managed to read it in in base-r with: spectra_gr2 <- read.csv("~/some/path/spectra.csv", header = F, encoding =…
m4D_guY
  • 166
  • 1
  • 11
3
votes
1 answer

read.csv converting empty character column to NA

Example: x <- data.frame(X = c("",""), Y=1:2, stringsAsFactors = F) write.csv("/tmp/temp.txt", row.names=F, quote=T) read.csv("/tmp/temp.txt") X Y 1 NA 1 2 NA 2 readr::read_csv("/tmp/temp.txt", col_types = list(col_character(), col_double())) …
thc
  • 9,527
  • 1
  • 24
  • 39
3
votes
3 answers

What are permissible column objects of the form "col_*()" used in readr?

readr::read_csv is misreading some column types in a file I am loading so I want to use cols to set them manually. In ?read_csv, it says the col_types argument should be _"One of ‘NULL’, a ‘cols()’ specification, or a string. See…
Jesse Anderson
  • 4,507
  • 26
  • 36
3
votes
0 answers

Error when trying to read an .xz file in R with readr functions

Sorry if I am not clear enough, this is my first question. I am not able to read an .xz file using different functions from package readr. In different parts of my code I have the following lines: dat <- read_lines(filename, progress = F, n_max =…
Vecino
  • 41
  • 5
3
votes
2 answers

Negative currency values using parse_number in readr R

I'm importing sales data that needs to be converted from character strings to numeric. I'm trying to use parse_number in readr to do this, but it throws a parsing error for negative values, and coerces them to NAs. As an example: x <-…
Ash Levitt
  • 153
  • 3
  • 11