简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM