Commit 68e2427f authored by Quentin Read's avatar Quentin Read
Browse files

read.csv.better() and file to test it on

parent c4f8e0c4
# A wrapper function for read.csv that uses perl to convert any possible spaces to a single type and then reads the CSV with
# any other arguments to read.csv that you want to input.
# Example output where file_path refers to a CSV containing a single string with lots of different types of spaces, in this repo.
# Bad:
# read.csv("spcs.csv", header = FALSE)
# V1
# 1 X           â\u0081Ÿã€€X
# Better:
# read.csv.better(file_path, header = FALSE)
# V1
# 1 X X
read.csv.better <- function(file_path, ...) {
read.csv_args <- list(...)
txt <- system2("perl", args = paste("-CSDA -plE \"s/\\s/ /g\"", file_path), stdout = TRUE)
conn <- textConnection(txt)
do.call(read.csv, args = c(list(file = conn), read.csv_args))
}
X             X
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment