Question

I am trying to use the R package xlsx to load a file available at this URL: http://www.plosgenetics.org/article/fetchSingleRepresentation.action?uri=info:doi/10.1371/journal.pgen.1002236.s019

library(xlsx)
filename="/home/avilella/00x/mobile.element.insertions.1000g.journal.pgen.1002236.s019.xlsx"

system(paste("ls -l",filename))
-rw-rw-r-- 1 avilella avilella 2372143 2011-12-11 16:36 /home/avilella/00x/mobile.element.insertions.1000g.journal.pgen.1002236.s019.xlsx

Once downloaded, I try to load it in R using read.xlsx or read.xlsx2:

file <- system.file("mobile.element.insertions.1000g", filename, package = "xlsx")
res <- read.xlsx2(file, 1)  # read first sheet

But I get an error:

Error in .jnew("java/io/FileInputStream", file) : java.io.FileNotFoundException: (No such file or directory)

Any ideas?

Était-ce utile?

La solution

1) xlsx package. Try using file.choose which will allow you to interactively navigate to the file and thereby eliminate the possibility of misidentifying it:

fn <- file.choose()
DF <- read.xls(fn, 1)

2) gdata package. If the above still does not work then you might try read.xls in gdata. It uses a perl program rather than java. It can read both xls and xlsx files and can read data right off the net (downloading it into a temporary file and reading it from there in a manner that is transparent to the user):

library(gdata)
URL <- "http://www.plosgenetics.org/article/fetchSingleRepresentation.action?uri=info:doi/10.1371/journal.pgen.1002236.s019"
DF <- read.xls(URL)

?read.xls in gdata has more info.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top