0

I will appreciate very much your help fixing this issue: my code aims to read the data set, an Excel file (xlsx), from the internet. However, while running the code, it ends up with errors.

So, my code is:

library(xlsx)

# The link below does exist and the file is downloadable via a browser
l <- "https://www.rbnz.govt.nz/-/media/ReserveBank/Files/Statistics/tables/b2/hb2-daily.xlsx"

# 1st way to read the data...
read.xlsx(l, sheetName = "Data", startRow = 5)

# ... it produces an ERROR:
# Error in loadWorkbook(file, password = password) : 
#     Cannot find https://www.rbnz.govt.nz/-/media/ReserveBank/Files/Statistics/tables/b2/hb2-daily.xlsx

# 2nd way to read the data...
perl1 <- "C:/Strawberry/perl/bin/perl.exe"
options(java.parameters = "-Xmx1000m")

tmp <- tempfile()
download.file(l, destfile=tmp, method="curl")
rbnz.rates <- read.xlsx(file = tmp, sheetName = "Data", startRow = 5)
unlink(tmp)

# ... it produces an ERROR:
# Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl,  : 
#    java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
Alex
  • 161
  • 6
  • There is javascript working behind the scenes... You probably need to use `RSelenium` for downloading. – danlooo Oct 04 '21 at 12:03
  • I found no javascript, but you need to include `download.file(..., mode="wb")`. – r2evans Oct 04 '21 at 13:12
  • Does that (and https://stackoverflow.com/q/28325744/3358272) resolve your issue? – r2evans Oct 04 '21 at 13:15
  • Nothing of the above seems helping in my case. I think I have some issues with Java. How should (re)install it so that my RStudio works fine again? – Alex Oct 04 '21 at 14:19
  • I did reinstall Java on the PC, now I have a 64 bit Java. Now, it works well. Thank you very much! – Alex Oct 04 '21 at 16:01

0 Answers0