13

I wanted to use fread function to load all the datasets as I think it would better to use one type of import function so I just sticked to the fread.

Few of my files are in xlsx format and I was saving them to csv format and then using the fread function was trying to load the datasets.

But I noticed that when I converted the xlsx files into csv, an empty or incomplete row was being created in the newly created csv files.

Is there a way I can resolve this issue? Can I load xlsx file somehow using the fread function rather than converting it to csv file and then loading it using the fread function?

2
  • 2
    The short answer is that you can't read xlsx files with fread, xlsx files have a very different format to the text files that fread is designed for. Commented Jan 18, 2018 at 2:58
  • 3
    @Marius so the best option is to load the xlsx directly using readxl function and csv files using fread? Commented Jan 18, 2018 at 3:03

1 Answer 1

10

Here's how: Using command line tools directly in conjunction with csvkit like this

my.dt<-fread('in2csv my.xls') 
Sign up to request clarification or add additional context in comments.

4 Comments

How/where did you install csvkit? I could not find a good tutorial to get in working with R. When using your code, i initially got the error: 'in2csv' is not recognized as an internal or external command. After i follow the installation instructions on csvkit.readthedocs.io/en/1.0.3/tutorial/… and use: pip install csvkit in cmd, i get the error c:\users\francis\appdata\local\programs\python\python36\lib\importlib_bootstrap.py:219: ImportWarning: can't resolve package from spec or package, falling back on name and path. Any ideas?
well - you've got the right idea that csvkit needs to be installed separately and needs to be on your PATH for fread to pick it up... however the specifics of getting it to work in your python environment are beyond my ability to help. Here's someone else's advice I can not vouch for: github.com/wireservice/csvkit/issues/937
Thanks @malcook, it seems like im not the only one!
How to get csvkit in R?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.