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
0 answers

Exporting csv in R with trailing zeros

I have a data frame with time series values. The time stamp column is formatted as > trial_sub$time[8:15] [1] "500.0008" "500.0009" "500.0010" "500.0011" "500.0012" "500.0013" "500.0014" "500.0015" When I try to export the data frame as a csv, no…
JaredS
  • 242
  • 2
  • 5
  • 16
1
vote
1 answer

How to use readr::write_delim() to write a .csv enclosed

I am trying to build a file in S3 using write_delim and I wanted it enclosed with double quotes(") however I don't know if it is not a parameter in write_delim function and I will need to use a base R function or if I am doing it incorrectly. Here…
1
vote
1 answer

R: "Error: unexpected string constant in" with read_fwf()

I am trying to read a fixed width file from U.S. Census Bureau into R using read_fwf(). I keep getting an error in the same place in the list of column names. I have tried to change the particular column name at the location in multiple attempts and…
John Polo
  • 547
  • 1
  • 8
  • 25
1
vote
1 answer

How to accumulate the results of readr::read_lines_chunked?

I'm using readr::read_lines_chunked in the following way: if(!require(readr)) install.packages("readr", repos = "http://cran.us.r-project.org") mytb <- NULL read_lines_chunked(file="/tmp/huge.xml", chunk_size=10, callback = function(xml, pos) { …
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
1
vote
1 answer

Reading blocks of text into R with parsing errors

I am reading the of functions of a package of mine into R replacing some of the variables then saving the files again. This is to standardise the naming of the functions throughout the package. The code declares no errors or warnings on the…
Jonno Bourne
  • 1,931
  • 1
  • 22
  • 45
1
vote
3 answers

How to delete duplicated columns in a tibble in the tidyverse

Let's say my data has two identical columns called SYC SJ Equity. When I import this into R using the base read.csv() and setting check.names to FALSE, the data gets imported with two columns having identical names. I can then delete the duplicated…
Mr.Rlover
  • 2,523
  • 3
  • 14
  • 32
1
vote
0 answers

readr:type_convert() fails with substring errors

I am trying to initialise an empty tibble, with column names column types already specified. code below successfully initialise an empty tibble with names coltest <- c("exectime", "jancode", "publisher_code", "price_a", "price_b", "title", …
taiyodayo
  • 331
  • 4
  • 13
1
vote
2 answers

Unused argument (sep=";") error happens with all CSV files

I'd like to open a random csv-file like New_York_City_Leading_Causes_of_Death.csv (just a dummy, from a tutorial but happens with my own data the same way; replaced , with…
robin
  • 23
  • 1
  • 5
1
vote
1 answer

R - IMDb datasets not loading

I'm trying to write a function which will download and load files from IMDb dataset page available here: https://datasets.imdbws.com/ Problem is that function execution is downloading the file, but loading it to any object. I have created separate…
Supek
  • 47
  • 1
  • 7
1
vote
2 answers

How to use col_types using readr's read_delim_chunked?

I am trying to read a file in chunks and specify the col_types, see MWE write.csv(cars, "cars.csv") library(readr) readr::read_delim_chunked("cars.csv", function(x, i) { x }, delim= ",", col_types = cols( speed = col_character() ), chunk_size…
xiaodai
  • 14,889
  • 18
  • 76
  • 140
1
vote
1 answer

Extracting data from *.txt output file into R

I have an output.txt file that results from an analysis I am doing in R. I would like to extract: The << Output >> tables from the .txt file for each subject and combine them into an R data frame. The output column names are consistent between each…
Amer
  • 2,131
  • 3
  • 23
  • 38
1
vote
2 answers

parse chr string into a dataframe using delimiters

My data is in a format, that looks like this: t2 <- "a = 10\n b = 2\n c =20\n" How can I parse it so that I get a dataframe that looks like this? # a 10 # b 2 # c 20 I'm trying to use readr::format_delim(), but I'm happy to use any solution.…
Jeremy K.
  • 1,710
  • 14
  • 35
1
vote
1 answer

Read character datetimes without timezones

I am trying to import in R a text file including datetimes. Times are stored in character format, without timezone information, but we know it is French time (Europe/Paris). An issue arise for the days of timezone change: e.g. there is a time change…
jlesuffleur
  • 1,113
  • 1
  • 7
  • 19
1
vote
1 answer

read_csv (readr, R) populates entire column with NA if there are NA in the fist 1000 + x observations in a simple and clean csv (parsing failure)

I was just going through a tremendous headache caused by read_csv messing up my data by substituting content with NA while reading simple and clean csv files. I’m iterating over multiple large csv files that add up to millions of observations. Some…
MsGISRocker
  • 588
  • 4
  • 21
1
vote
1 answer

How to read a fixed width file knowing column names but not the widths?

I recently encountered a problem where we had a fixed width file. For example - Name Income John $10,000 Mary $15,000 Walter $25,000 How to read the fixed width files using just the column names?
Slayer
  • 832
  • 1
  • 6
  • 21