-3

I have an excel file that is stored on http:..../test.xls, how do i import this file into R ?

I tried using the gdata package but it requires Perl and I cannot install Perl on my office machine.

bison2178
  • 747
  • 1
  • 8
  • 22
  • 1
    Try the `readxl` package: https://github.com/hadley/readxl. It has no external dependencies so it's easy to install and use on all operating systems – Steven Beaupré Jul 21 '15 at 17:07
  • 1
    A good way is `read.xlsx(file)`using the `xlsx` package. It requires `Java` though. Hope you can install it or have it already on your computer. – RHertel Jul 21 '15 at 17:07
  • But you may have to download the file first with `download.file` or the RCurl package or httr or something rather than getting it directly from an http:// URL. Or maybe that's handled in the readxl package? – Spacedman Jul 21 '15 at 17:12
  • @Spacedman `readxl` uses `download.file` internally: https://github.com/jentjr/readxl/commit/0fb50846a110d63e53e3537c02fc66c63c71acc6 – Steven Beaupré Jul 21 '15 at 17:14
  • possible duplicate of [Read an Excel file directly from a R script](http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script) – MichaelChirico Jul 21 '15 at 17:45

3 Answers3

3

When you installed R there were several documents that installed with it (one way to see these docs is run the command help.start()). One of these documents is called "R Data Import/Export", section 9 of that document is titled "Reading Excel Spreadsheets" and it gives multiple options along with some discussion of what requirements there are for each.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
1

You could use readxl (installation instruction here)

The readxl package makes it easy to get data out of Excel and into R. Compared to many of the existing packages (e.g. gdata, xlsx, xlsReadWrite) readxl has no external dependencies so it's easy to install and use on all operating systems. It is designed to work with tabular data stored in a single sheet.

Note: As per mentionned by @Spacedman, you may have to download the file first using download.file or your favorite Curl package.

You could also use jentjr's fork which adds URL capability to readxl by using download.file internally:

devtools::install_github("jentjr/readxl")
library(readxl)

idem_url <- "http://www.in.gov/idem/files/groundwater_gwmn_data_2008.xls"
gw <- read_excel(idem_url)
Steven Beaupré
  • 21,343
  • 7
  • 57
  • 77
1

I suggest library xlsx. Please check method ?read.xlsx

milos.ai
  • 3,882
  • 7
  • 31
  • 33