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
1
vote
1 answer

readr issue with read_delim not including decimals

I'm trying to read a csv file that looks like this (Let's call this test1.csv) test_1;test_2;test_3;test_4 Test with Ö Ä;20;10,45;15,34 As you can see, the values are separated by ; and not , - in fact , is the decimal separator. I've added "Ö" and…
Moritz Schwarz
  • 2,019
  • 2
  • 15
  • 33
1
vote
1 answer

R: How to merge multiple data frames when some columns have different names

I am trying to merge some csv files into one large data frame using the following code: library(tidyverse) list_of_files = list.files(path = "/home/maanan/Downloads/NYCData/2017/", recursive = TRUE, pattern = "\\.csv$", full.names = TRUE) df =…
Saïd Maanan
  • 511
  • 4
  • 14
1
vote
2 answers

Apply an `as.character()` function to a list of dataframes

So essentially I have a list of dataframes that I want to apply as.character() to. To obtain the list of dataframes I have a list of files that I read in using a map() function and a read funtion that I created. I can't use map_df() because there…
Hansel Palencia
  • 1,006
  • 9
  • 17
1
vote
1 answer

Using locale's date_format in readr

How do I correctly set locale's date_format to work with cols() from readr? Instead of specifying the date format for every column: df <- read_csv2(my_file, col_types = cols(.default = '?', my_date =…
user1
  • 404
  • 1
  • 5
  • 18
1
vote
3 answers

r: read_csv, cols(): Specify multiple column types at once

Is it possible to specify multiple column types with one assignment in cols() from read_csv? Instead of: read_csv2(my_file, col_types = cols(.default = 'i', logi_one = 'l', logi_two =…
user1
  • 404
  • 1
  • 5
  • 18
1
vote
1 answer

R: extract dates and numbers from PDF

I'm really struggling to extract the proper information from several thousands PDF files from NTSB (some Dates and numbers to be specific); these PDFs don't require to be OCRed and each report is almost identical in length and layout information. I…
Andrei Niță
  • 517
  • 1
  • 3
  • 14
1
vote
1 answer

How to parse chunk of CSV data with white space line breaks into list of data frames

I have the following text file, it contains several chunk of table. Each chunk is separated by white space. GENERALIZED BORN: Complex Energy Terms Frame #,BOND,ANGLE 0,6603.0521,7264 1,7434.9885,7602 Receptor Energy Terms Frame…
littleworth
  • 4,781
  • 6
  • 42
  • 76
1
vote
4 answers

How to parse dates from a string without writing a regular expression?

readr package has a function called parse_number that returns the numbers in a string: readr::parse_number("Hello 2022!") [1] 2022 Is there a similar method for returning a date from a string? The readr has a function called parse_date but it does…
bird
  • 2,938
  • 1
  • 6
  • 27
1
vote
1 answer

Set read_csv() to a fixed number of columns?

TLDR: How do I set Rstudio to import a CSV as a tibble exactly as Microsoft Excel (Rstudio for mac version: Version 1.3.959, Excel for mac: version 16.33 if that helps)? If this is not possible or it should already behave the same, how do I set it…
1
vote
3 answers

writing and reading class of columns to csv

For a dataframe, I'd like to save the data class of each column (eg. char, double, factor) to a csv, and then be able to read both the data, and the classes, back into R. For example, my data might look like this: df #> # A tibble: 3 × 3 #> item …
Jeremy K.
  • 1,710
  • 14
  • 35
1
vote
2 answers

R: write_csv without messing up the language

I am working with a dataset that contains data in multiple languages. Is there a way to export my work as a CSV file and have R maintain the use of characters in a foreign language instead of replacing them with gibberish English symbols?
MOliver
  • 87
  • 6
1
vote
1 answer

R readr:read_csv() incorrectly reads character vectors if all strings begin with "Inf" (e.g. "Inform")

I'm seeing unexpected behavior from the excellent readr::read_csv(). When trying to read a tibble containing a character vector of strings that all begin with "Inf" (e.g. "Inform", "Information"), read_csv() incorrectly reads it as a numeric Inf,…
sdevine188
  • 338
  • 3
  • 8
1
vote
3 answers

Apply readr col_cpec to data.frame, independently of reading from file

I have a tibble (data.frame) that I need to apply a number of type updates to. I have a readr::col_spec object that describes the desired types, but since the data does not originate as a csv file, I cannot use read_csv(..., col_types=cspec) to…
Magnus
  • 23,900
  • 1
  • 30
  • 28
1
vote
0 answers

R readr col_types specified in a metadata file, specifically using custom date formats

I want to use a metadata file to read in column formats to use in readr. And some of the formats I need to specify are custom date formats. So instead of hardcoding the column_formats like this... readr::read_csv(readr_example('mtcars.csv'), …
moreQthanA
  • 43
  • 9
1
vote
1 answer

select subset of columns when using col_type() in readr

I'm trying to read in a file with read_delim() and select a subset (a long run) of columns to define as a specific type. As an example, I have a file with 6 columns. I want to select column 1 ('name') as character, but then select columns 2-6 as…
jamill0
  • 13
  • 3