0

I have a excel file(both xls and xlsx format) with multiple sheets. I have installed readxl package in R. I tried with the below code to import specific sheets, specific rows to columns but getting the error

 install.packages("readxl")
 library("readxl")
 sam1 <- read_excel("File1","Sheet1",rowIndex = 6:8,colIndex = 1:13)

Error in read_excel("File1", "Sheet1", rowIndex = 6:8, : unused arguments (rowIndex = 6:8, colIndex = 1:13)

Can we solve this?

Rahul H
  • 35
  • 5
  • Are ``rowIndex`` and ``colIndex`` even arguments in the ``readxl::read_excel()`` function? Couldn't you use the ``range`` argument to choose the cells you want? Something like : ``read_excel("File1","Sheet1", range = cell_rows(102:151))`` you can also use it for cols with ``range = cell_cols("B:D"))`` – Gainz Aug 28 '19 at 17:48
  • 1
    I think you are mistaking the ``readxl`` package for the ``xlsx`` package. The ``xlsx`` package is the one having ``rowIndex`` and ``colIndex`` argument in its function. – Gainz Aug 28 '19 at 17:54

1 Answers1

1

You are probably mistaking the readxl package with the xlsx package. Both of them have a read_xlsx() function with different arguments tho.

The result you want can be achieve with the xlsx package. You simply have to install the package :

install.packages("xlsx")
library("xlsx")
sam1 <- read_excel("File1", "Sheet1", rowIndex = 6:8, colIndex = 1:13)

or

sam1 <- xlsx::read_excel("File1", "Sheet1", rowIndex = 6:8, colIndex = 1:13)
Gainz
  • 1,721
  • 9
  • 24
  • Not possible i tried I get error like Error: .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures. – Rahul H Aug 28 '19 at 18:13
  • Yes that is probably a problem with your java version (example Windows 64-bit and Java 64-bit). You could also try to install ``rJava`` You can't run the ``readxl`` package to run a function from the ``xlsx`` package so you should go take a look here to fix your java problem : https://stackoverflow.com/questions/17376939/problems-when-trying-to-load-a-package-in-r-due-to-rjava and then try to install the ``xlsx`` package. Otherwise you can use ``readxl::read_excel()`` and give a try to the ``range`` argument. – Gainz Aug 28 '19 at 18:16