Sebastian Zeki
Sebastian Zeki

Reputation: 6874

Referencing worksheets in excel spreadsheet by index rather than name in r

Im trying to use XLconnect in order to import worksheets as my datasource

If I use the code below I get the subsequent error

 library(XLConnect)
 wk = loadWorkbook("/Users/sebastianzeki/Desktop/SequencingScripts/bedtools/bedtools2-master/CohortComparisons/PanCancerCommonSCNAs.xlsx")
amp_genesAll_cancer = readWorksheet(wk, sheet="amp_genes.All_cancer.txt", header=TRUE)
Error: IllegalArgumentException (Java): Sheet index (-1) is out of range (0..25)

One work around would be to convert the names to numbers of the worksheets but I still need to have control over how each one is imported rather than importing all into one dataframe. Not sure how to do this though

Upvotes: 0

Views: 504

Answers (1)

Chris
Chris

Reputation: 6372

Assuming your wk = code runs correctly, and you see a 'formal class workbook' object appear, you have likely misspelled your sheet name. The index -1 means that your string given as the title does not match.

To use indexes, use:

amp_genesAll_cancer = readWorksheet(wk, sheet=1, header=TRUE)

With 1 being the sheet number

Upvotes: 1

Related Questions