Using library function to load XLConnect results in Errors

Hello, I'm a new user to the community.
I'm running into trouble trying to load "XLConnect". I have installed the package OK, but trying to use library(XLConnect) just results in an error. I have copied the text of the error if that might help:

"package or namespace load failed for ‘XLConnect’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures."

I re-installed Java version 8 to my PC but that hasn't made any difference. I'm wondering if I could get some advice on what to do next? How to go about resolving this issue?

A couple things to try:

  • Run sudo R CMD javareconf in a system terminal and
    restart your R session.

  • Set the path to your Java executable by defining the JAVA_HOME environment variable in a .Renviron file and restart your R session.

Thank you for your reply Andre,
I'm a little bit new to RStudio and I must admit I'm not sure I understand your instructions. I want to try them out but I'm not sure how to carry out your instructions. Could you simplify them for me please?
e.g. I don't understand what a "system terminal" is? I don't know how I do the second part of your help. Sorry, I've only been using RStudio for a few months. I would appreciate your help in simplifying them for me.
It would help if you said, go to X and do Y, basic instructions that I can follow. Keep it simple please?
Thanks again for your reply.

Hard to give detailed instructions like that without any information about your system. Please tell us what operating system you are using and if you have installed a version of the Java Development Kit (not the Java Runtime Environment).

My system runs on Windows 10. I don't have an installed copy of Java Development Kit, just the Runtime Environment. I have an Intel i7, 32 GB Ram, DDR4, SSD C: drive and a 2TB Storage disk (D:). Office 365. I hope that helps. I'm learning R, following the book R for Dummies, so I'm relatively new to R. I have R 4.2.2 installed. I'm using RStudio (Posit). Not sure what else you may need to know but I'm happy to let you know. Thanks for following through on my post.
Much Appreciated,

I believe you need to install one. XLConnect imports rJava and this package requires a JDK installation. Maybe this is all you need to make it work.

If it doesn't automatically recognize the JDK installation then you might need to create a text file called .Renviron in your HOME folder and define the JAVA_HOME variable inside, for example:

JAVA_HOME="C:/Program Files/Java/jdk-11.0.1/"

After that, restart your R session and try to load the library again

I have installed the JDK 19.01. When you say my HOME folder do you mean my R Working Directory?

Maybe but not necessarily, usually your default working directory is set to the system's HOME directory but that might have been changed.

To avoid any misunderstanding maybe is better if you use an R-version level file in this location "C:/Program Files/R/R-4.2.2/etc/

Sorry Andre, I'm not quite with you there. I have made a Notepad file which insists on putting the .txt extension on the .Renviron file, will that be OK? It says, .Renviron.txt is that OK?

No, the file needs to be called .Renviron (for the user-level file) or (for the R-version level file).
Notepad can save the file just fine but if you are having problems, simply modify the name afterwards.

I'm lost now. .Renviron for the user-level file, I don't know what that means. OR (for the R-version level file).
OK I can change the name of the file. There are 2 files I need to make now?

No, you said you didn't knew where your HOME folder is, that is why I gave you a second option with an exact location, you can choose either one.

OK, I put the .Renviron file into my R working directory, (which I think is what you called HOME), that file is in that location now. D:\Data\Data Science\Learning\R for Dummies\Working
That is where I have put .Renviron (as you said I changed the name to remove the .txt extension from Notepad. Is that all I need to do? That text file has the JAVA_HOME path in it. Is that right?

No, it is not the same, your user's HOME folder is defined by the operating system, it is not a synonymous for your R's current working directory. And the .Renviron file is not going to get loaded from that location when you restart your R session (unless you are on an RStudio Project).

The HOME folder is a general computer stuff concept, if you are not familiar with it, use the second option I gave you.

I'm learning R. What I know is that it is supposed to have something called a "Working" directory, which I have which is where I have put .Renviron file. I thought that was where the file was supposed to go.
OK, I chose that.

Perhaps I'll try loading the XLConnect package? If no good I'll try the second option?

That's it! Thank you Andre, XLConnect has successfully loaded now! Yippee! Thank you very much for your patient help! I hope you get to help me in the future.
Thanks from Down Under Australia

The working directory is simply the directory from where you are currently executing the code, it can be changed arbitrarily. As far as I can recall, R will only load startup files from the working directory if you are loading an RStudio project, otherwise will only load files present in your HOME directory or in the the C:/Program Files/R/R-4.2.2/etc/ folder.

So I need to know the full path of what you are calling HOME. You said it was,
C:/Program Files/R/R-4.2.2/. So I was wrong in calling the Working directory HOME. So I'll use the second option and put the file in the R path. I have done that now, I'll delete the file I put in my working directory.

I'm not sure what the full path is to the R HOME folder. I have put into the
C:/Program Files/R/R-4.2.2/. Is there any further extension to that path?

I already told you that

BTW, I never said that, and that is not your HOME folder. Also, it is not "what I'm calling it", as I said, it is a general computing concept, not something I'm madeing up