1

I'm trying to install 'xlsx' through install.packages('xlsx') and this shows me

Warning in install.packages :``
cannot open URL 'https://cran.rstudio.com/bin/macosx/el- 
  capitan/contrib/3.4/PACKAGES.rds': HTTP status was '404 Not Found'
trying URL 'https://cran.rstudio.com/bin/macosx/el-
 capitan/contrib/3.4/xlsx_0.5.7.tgz'
Content type 'application/x-gzip' length 401263 bytes (391 KB``)
downloaded 391 KB
The downloaded binary packages are in
/var/folders/tt/2_by_ybs0tb3fd0_xv2v2xbw0000gn/T//Rtmpa3VNMs/downloaded_packages

After some research, I found out that I needed to install rJava and it seemed fine. When I click xlsx and rJava through 'packages', it showed me

library("xlsx",
lib.loc="/Library/Frameworks/R.framework/Versions/3.4/Resources/library")
Loading required package: rJava
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object >' 
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.>so': 

dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/>    rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
 Referenced from: > 

/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.s>o
 Reason: image not found
Error: package ‘rJava’ could not be loaded

and this is for rJava

library("rJava", >lib.loc="/Library/Frameworks/R.framework/Versions/3.4/Resources/library")
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object >'/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.>so':
  >dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/>rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: >/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.s>o
Reason: image not found

I was wondering what happened and want to know how to fix it. I am using a MacBook Air from 2015. Some people say 3.4.0 doesn't support xlxs or rJava yet. It would be so helpful if you tell me how to go through these issues step by step.

alistaire
  • 42,459
  • 4
  • 77
  • 117
KingJinho
  • 683
  • 1
  • 6
  • 23
  • 2
    **a.** It's rJava that's the problem. **b.** It's a hard problem. `R CMD javareconf` can help, but you almost certainly need to build rJava from source and set some environment variables telling it where your Java install is. Ultimately it's solvable (I have it running on Sierra), but the particulars are miserable. **c.** There are good alternatives that don't require Java, namely [readxl](https://github.com/tidyverse/readxl) and [openxlsx](https://github.com/awalker89/openxlsx). – alistaire Jul 10 '17 at 03:35
  • R 3.4.x supports rJava on the Mac. In fact the maintainer of the Mac fork of R (Simon Urbanek) is that same as the maintainer of rJava. You need to install the proper version of the JRE which I believe is currently version1.8. Do some searching on installing the Java Runtime Environment. (You note the machine but not the OS.) I suspect that the answer is in one or more of the answers to https://stackoverflow.com/questions/37911387/i-cannot-run-r-xlsx-package-on-my-mac-os-10-11-5-el-capitan (My machine is early 2008 running El Cap.) – IRTFM Jul 10 '17 at 06:43
  • Have you tried to use the readxl package instead? No need of Java, then: [https://cran.r-project.org/web/packages/readxl/readxl.pdf](https://cran.r-project.org/web/packages/readxl/readxl.pdf) – YCR Jul 10 '17 at 10:36

1 Answers1

0

Take a look at the location here: R, Java, rJava and macOS adventures

You can find there description of how to deal with Java, R, rJava inside macOS. There is some mess, generally, there. You have to pay attention to few things like:

  • location of JDK,
  • making sure R points to proper libs,
  • making sure you are using Oracle's based JDK.

Eventually, you should get it running once setting all the stuff in place.

I don't post full description here as it's quite long. Also, pay attention to JDK settings that allow to run JNI based codes. You need to make sure that JDK has proper settings inside

`/usr/libexec/java_home`/../Info.plist

Lots of things to be done, but eventually, it should work :)

Have fun with R.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45