Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ci-misc
R-utility-belt
Commits
68e2427f
Commit
68e2427f
authored
Aug 26, 2020
by
Quentin Read
Browse files
read.csv.better() and file to test it on
parent
c4f8e0c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
read.csv.better.R
0 → 100644
View file @
68e2427f
# 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
))
}
spcs.csv
0 → 100644
View file @
68e2427f
X X
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment