1sheetCount <- function(xls, verbose = FALSE, perl = "perl") { 2 perl <- if (missing(perl)) findPerl(verbose = verbose) 3 else findPerl(perl, verbose = verbose) 4 sheetCmd(xls, cmd="sheetCount.pl", verbose=verbose, perl=perl) 5} 6 7sheetNames <- function(xls, verbose = FALSE, perl = "perl") { 8 perl <- if (missing(perl)) findPerl(verbose = verbose) 9 else findPerl(perl, verbose = verbose) 10 sheetCmd(xls, cmd="sheetNames.pl", verbose=verbose, perl=perl) 11} 12 13sheetCmd <- function(xls, cmd="sheetCount.pl", verbose=FALSE, perl="perl") 14{ 15 16 ## 17 ## directories 18 package.dir <- find.package('gdata') 19 perl.dir <- file.path(package.dir,'perl') 20 ## 21 ## 22 23 ## 24 ## files 25 tf <- NULL 26 if ( substring(xls, 1, 7) == "http://" || 27 substring(xls, 1, 6) == "ftp://" ) 28 { 29 tf <- paste(tempfile(), "xls", sep = ".") 30 if(verbose) 31 cat("Downloading", 32 dQuote(xls), " to ", 33 dQuote(tf), "...\n") 34 else 35 cat("Downloading...\n") 36 download.file(xls, tf, mode = "wb") 37 cat("Done.\n") 38 xls <- tf 39 } 40 ## 41 42 sc <- file.path(perl.dir, cmd) 43 44 ## 45 ## 46 47 ## 48 ## execution command 49 50 cmd <- paste(shQuote(perl), shQuote(sc), shQuote(xls), sep=" ") 51 ## 52 ## 53 54 ## 55 ## do the translation 56 if(verbose) 57 { 58 cat("\n") 59 cat("Extracting sheet information from\n") 60 cat(" ", dQuote(xls), "\n") 61 cat("... \n\n") 62 } 63 ## 64 output <- system(cmd, intern=TRUE, ignore.stderr=TRUE) 65 if(verbose) cat("Results: ", output, "\n") 66 ## 67 tc <- textConnection(output) 68 results <- read.table(tc, as.is=TRUE, header=FALSE) 69 close(tc) 70 results <- unlist(results) 71 names(results) <- NULL 72 ## 73 if (verbose) cat("Done.\n\n") 74 75 results 76} 77 78 79