0

I have a xlsm file (please look at the photo below) and I want to:

  • Skip the first 4 rows
  • Use the 5th row as variables names

I tried with read_csv("Sujet8.xlsm", skip = 4) but it returned me this error:

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
no lines available in input
In addition: Warning messages:
1: In readLines(file, skip) : line 1 appears to contain an embedded nul
2: In readLines(file, skip) : line 2 appears to contain an embedded nul
3: In readLines(file, skip) : incomplete final line found on 'Sujet8.xlsm'

I tried also readxl package.

data_types = c("text","text")
my_data = read_excel("Sujet8.xlsm", sheet = "Sheet2", skip = 4, na = "n/a", col_types = data_types)

But it returned me this error:

Error in read_fun(path = path, sheet = sheet, limits = limits, shim = shim,  : 
Sheet 1 has 52 columns, but `col_types` has length 2.

How can I fix this? Sorry I can't share the file because it is for internal use only. But here is how it looks.

enter image description here

SiXUlm
  • 159
  • 3
  • 12
  • The error is rather clear - you provided column types for only *two* columns when the table has a lot more. According the error, it has 52 columns. – Panagiotis Kanavos Feb 28 '18 at 09:46
  • Your screenshot shows the data has many types, not just 2. The first is a date, not text, although you probably have to read it as text to parse it. The 2nd, 3rd, 4th are definitely numbers. Probably all of them are numbers? Have you tried calling `read_excel` *without* passing any data types and let it guess the types? – Panagiotis Kanavos Feb 28 '18 at 09:47
  • Furthermore, Excel is *NOT* a `csv` file. `CSV` is just text. Excel files are zip-packaged xml files. `read_csv` would never work with Excel or PDF or Word files. – Panagiotis Kanavos Feb 28 '18 at 09:49
  • The error talks about columns, not distinct types. It says there are 52 columns and it needs 52 types. If you don't want to specify the type for each column try calling `read_excel` without specifying the types. – Panagiotis Kanavos Feb 28 '18 at 09:52
  • Ah I see, you are correct. It works now. Many thanks!!! – SiXUlm Feb 28 '18 at 09:57

0 Answers0