Problem loading rJava - r

Yesterday I removed R2.11 from my system (Win7, 64bit), since I´m working on R2.13.
Since then i get an error message:
> require(rJava)
Lade nötiges Paket: rJava
Error : .onLoad in loadNamespace() fehlgechlagen, Details:
Aufruf: rJava
Fehler: inDL(x, as.logical(local), as.logical(now), ...)
I tried specifying PATH, since I found on the internet that it might have something to do with jvm.dll:
c:\Rtools\bin;
c:\Rtools\perl\bin;
c:\Rtools\MinGW\bin;
c:\Rtools\MinGW64\bin;
C:\Windows\system32;
%R_HOME%\bin;
C:\Program Files\R\R-2.13.0\bin;
C:\Program Files\Java\jre6\bin\server
However I could not solve the problem...
I also can´t run R from the win command line (just type "R"?)
Any suggestions?

Here is some quick advice on how to get up and running with R + rJava on Windows 7 64bit. There are several possibilities, but most have fatal flaws. Here is what worked for me:
Add jvm.dll to your PATH
rJava, the R<->Java bridge, will need jvm.dll, but R will have trouble finding that DLL. It resides in a folder like
C:\Program Files\Java\jdk1.6.0_25\jre\bin\server
or
C:\Program Files\Java\jre6\jre\bin\client
Wherever yours is, add that directory to your windows PATH variable. (Windows -> "Path" -> "Edit environment variables to for your account" -> PATH -> edit the value.)
You may already have Java on your PATH. If so you should find the client/server directory in the same Java "home" dir as the one already on your PATH.
To be safe, make sure your architectures match.If you have Java in Program Files, it is 64-bit, so you ought to run R64. If you have Java in Program Files (x86), that's 32-bit, so you use plain 32-bit R.
Re-launch R from the Windows Menu
If R is running, quit.
From the Start Menu , Start R / RGUI, RStudio. This is very important, to make R pick up your PATH changes.
Install rJava 0.9.2.
Earlier versions do not work! Mirrors are not up-to-date, so go to the source at www.rforge.net: http://www.rforge.net/rJava/files/. Note the advice there
“Please use
`install.packages('rJava',,'http://www.rforge.net/')`
to install.”
That is almost correct. This actually works:
install.packages('rJava', .libPaths()[1], 'http://www.rforge.net/')
Watch the punctuation! The mysterious “.libPaths()[1],” just tells R to install the package in the primary library directory. For some reason, leaving the value blank doesn’t work, even though it should default.

I finally solved the problem:
It seems that rJava searches for jvm.dll in ~\Java\jre6\bin\client.
However this folder didn´t exist on my system (jvm.dll was in ~\bin\server).
So I just made a copy of jvm.dll in a folder ~\bin\client\ and added this to the path.
Now everything works fine!

My problem was solved by
install.packages("SqlRender",INSTALL_opts="--no-multiarch")
It was a package that depends on rJava and all advices were telling me to fix Java installation. But the solution was to use install option that simply forgets about i386 architecture. (also works with drat library and packages not from CRAN)

This may be due to a conflict between RStudio and Java versions. If you have installed 64 bit java and RStudio is running in 32 bit mode, you may experience problems like this. As a solution, you can change the 32-64 bit selection in the Tools-> Global Options-> General section in RStudio.
You can find detailed information here.

In my case installing proper version of Java solved my problem.
I installed 64x bit java, cause I use 64x bit R version.

I solved it by following these steps
setting my environment Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre6')
Manually installing rJava package from install package (even this should work:
install.packages('rJava', .libPaths()[1], 'http://www.rforge.net/'))
library(rJava)

I solved this problem as follows. I've been trying for 2 days.
Windows 7 users do not write ... \ bin \ x64 in environment variables.
Instead, define the path as follows.
JAVA_HOME "C: \ Program Files \ Java \ jre1.8.0_251"
R_HOME C: \ Program Files \ R \ R-3.5.3

In RStudio type .LibPaths()
This will give you an path in you windows system where your library’s are located
Go there and delete rJava. If it is being used by applications of Java, kill all Java programs in the Task Manager.
Go to computer and properties, click on change environment variables
Edit JAVA_HOME and all Java related paths to the path where your newest installation of Java is located and save.

Related

how to install RODBC on macOS Sierra 10.12.4

In R 3.4.0,
install.packages('RODBC', type='source')
fails on macOS 10.12.4. I also downloaded RODBC_1.3-15.tar.gz from CRAN and tried,
R CMD INSTALL RODBC_1.3-15.tar.gz
In both cases, I got "ODBC headers sql.h and sqlext.h not found". A discussion of this in Installation of RODBC/ROracle packages on OS X Mavericks says the following:
To fix this, you need to download the latest version of iODBC (www.iodbc.org), and then unzip the file and set your header and library search paths to the location where you put the unzipped package. If you don't know how to set your search paths, you could just put the header files (sql.h and sqlext.h) in the /usr/include directory, and the libiodbc.a file in the /usr/lib directory.
I downloaded iodbc-42.5.tar.gz and untarred it into a directory next to RODBC, untarred from RODBC_1.3-15.tar.gz. Sadly, I can't find how to set header and library search paths, and when I try to put the header files in /usr/include, the system won't let me.
iodbc-42.5/iodbc/README.MACOSX says,
You first need to install the latest Mac OS X Developer Packages, which can be found at http://developer.apple.com/tools
I think I've done that, but I don't know how to check it. [In fact, I think I've done it multiple times: The message ODBC headers sql.h and sqlext.h not found, disappeared for a while from the still-negative response to install.packages('RODBC', type='source'), only to reappear later after I successfully installed port and ran sudo port install gcc6. Then I got ODBC headers sql.h and sqlext.h not found again.]
iodbc-42.5/iodbc/README.MACOSX continues,
Then, you can open the Xcode Project Builder files under mac/iODBCinst, mac/iODBC, mac/iODBCtest and mac/iODBCtestw.
I don't know how find any of these. It further continues,
or execute the following commands from a terminal session to build all the frameworks and demo applications:
$ cd mac
$ make
I did $ cd mac and got -bash: cd: mac: No such file or directory. Evidently, I need to substitute something for mac here, but I don't know what. ???
Thanks.
I solved the problem with:
ODBC_INCLUDE=/path/to/libiodbc-srcs/include R CMD INSTALL RODBC
where "/path/to/libiodbc-srcs/include" is the path to the "include" folder containing the missing files, "sql.h" and "sqlext.h". In my case it was something like '~/Documents/Rstuff/iodbc-42.5/iodbc/include', which I checked with the following in R:
dir('~/Documents/current/Rstuff/iodbc-42.5/iodbc/include')
Then the following worked for me:
ODBC_INCLUDE=~/Documents/current/Rstuff/iodbc-42.5/iodbc/include R CMD INSTALL RODBC
This is described in p. 19 of https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf, except that contains a stray quote (<'>), which threw me off the first few times I read it, because was not familiar with that syntax.
On R-Sig-Mac, Marc Schwartz offered two suggestions: First, Installation of RODBC on OS X Yosemite, which may work with "brew"; I didn't try that, because I got the above to work first.
Second:
install.packages("RODBC", type = "source",
configure.args = "--with-odbc-include=/path/to/libiodbc-srcs/include/")
This should work also with the path substitution mentioned above.
I hope this helps someone else.

rJava library not working. Unable to find jvm.dll

I realize this question has been asked before but none of the solutions worked for me.
After a 'successful' install of rJava I try library(rJava) I receive an error that R cannot find jvm.dll. Here are the solutions I've tried:
Setting my PATH to include a direct link to the jvm.dll directory. Also tried one level up
Clearing the JAVA_HOME environmental variable. Also setting JAVA_HOME to the directory of my jvm.dll
Direct install from rforge.net using install.packages('rJava', .libPaths()[1], 'http://www.rforge.net/'). I receive this error:
Find Java...
ERROR: cannot find Java Development Kit.
Please set JAVA_HOME to specify its location manually
Attempted setting the path of JAVA_HOME using this command: options(java.home="C:\\Program Files (x86)\\Java\\jre1.8.0_121\\bin\\client")
Other potentially useful information:
Going into cmd and running echo %JAVA_HOME% shows the correct directory
I restarted RStudio after every attempt
Running on Windows 7 64 bit.
Any ideas would be greatly appreciated. Getting really frustrated trying to get this library working as it's needed for the xlsx library.
SOLUTION:
Egg on my face, the issue was that I accidentally pointed to environmental variable to an old 32 bit install of Java that I must have accidentally installed at some point in the last few years (thank you #user20650). Pointing everything back at the 64 bit version fixed things. For the record I did have to set JAVA_HOME to point to the correct directory. Also, make sure you have both the java JRE and JDK.
Egg on my face, the issue was that I accidentally pointed to environmental variable to an old 32 bit install of Java that I must have accidentally installed at some point in the last few years (thank you #user20650). Pointing everything back at the 64 bit version (ie C:\Program Files\Java\jdk1.8.0_121) fixed things after running install.packages('rJava', .libPaths()[1], 'http://www.rforge.net/').
For the record I did have to set JAVA_HOME to point to the correct directory. Also, make sure you have both the java JRE and JDK. Also, for some reason my anti-virus did not like letting that rforge install go through (didnt like the findjava.exe), so I had to pause it for a moment.

How to build qpdf on Windows?

When running the checks for my R-package (via devtools::check()) I face the warning ''qpdf' is needed for checks on size reduction of PDFs. I found this question were it was suggested (if I understood the answer correctly) to run Sys.which(Sys.getenv("R_QPDF", "qpdf")) and see whether qpdf is found or not. In my case this just returns
qpdf
""
so, I think I didn't install qpdf correctly. Unfortunately it seems to be quite complicated to install qpdf on Windows. My first side question is: does it really is so painful and complicated to install qpdf for Windows or is there an easy solution?
I've followed the instructions until it is said to add C:\MinGW-w64\bin and C:\MinGW-w64\lib\mingw to the PATH variable. But then I don't find further specific instructions to install qpdf, only about how to build qpdf with different other programs. The second side question is: is my assumption correct that after I've build qpdf it is installed? But the real question is: What is the best way to build qpdf? I tried the ./config-mingw32 and ./config-mingw64 commands from the section "Building with MinGW" in my C:\MinGW\msys\1.0\bin\bash.exe but got the error messages ./config-mingw32: No such file or directory and have no idea how to fix this issue.
I'm using Windows 10, R version 3.3.2 Patched (2017-01-07 r71934) -- "Sincere Pumpkin Patch" and RStudio 1.0.136.
You basically do not need to build the file on windows. Please follow three steps below:
Download qpdf for windows from https://sourceforge.net/projects/qpdf/?source=typ_redirect
Extract files in a temp folder
Copy the contents of the bin folder to %SystemRoot%\System32
job done!
Sys.which(Sys.getenv("R_QPDF", "qpdf"))
qpdf
"C:\\WINDOWS\\SYSTEM32\\qpdf.exe"
To flesh out an answer provided elsewhere:
If you are running the 32-bit version of R, it is important that you download the 32-bit version of qpdf, which is the version linked from the SourceForge homepage. If you are running a 64-bit installation of R, you will need to do a bit of digging to locate the 64-bit version of qpdf, which is buried a little more deeply (version 10.0.1 is listed here).
Rather than copying files to C:/Windows/System32, a potentially safer option is to extracted the zipped qpdf directory to C:\Program Files. If you do this, you'll need to add C:\Program Files\qpdf-version_number\bin to your system PATH under the environment variables.
To do this within R, run Sys.setenv('PATH' = paste0('C:\Program Files\qpdf-version_numer\bin;', Sys.getenv('PATH')))
To do this in Windows, open the start menu, type "edit the system environment variables" to open the System Properties, and at the bottom of the "Advanced" tab click "Environment variables". Find the "Path" entry under "System variables" and click "Edit". Then, re-start R so it picks up the modified PATH.
One further step may be required to convince Windows that pqdf is safe to run.
Navigate to C:\Program Files\qpdf-version_numer\bin and execute qpdf.exe (by double-clicking). Windows 10 throws up a security warning, as it's an unrecognized executable file. You'll need to use the more options link to find the button to run the program. This done, Windows will recognize the file as safe to run and allow other software, including R, to use it.

Architect / StatET: Launching R Console was cancelled because R engine failed

I recently upgraded to Architect version 0.9.7 on my Win 7 machine. However, after starting Architect, the RJ console wouldn't launch and I got the error message:
‘Launching the R Console was cancelled, because It seems starting the R engine failed.”
Please make sure that R package 'rj' (2.0 or compatible) is installed and
that the R library paths are set correctly for the R environment
configuration 'Embedded R Server'.
I installed the packages ‘rj’ and ‘rj.gd’ through the RTerm run console (which does happen to work) within Architect using the command suggested on www.walware.de:
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-2.0")
Then, I restarted windows, and restarted Architect. Same error message. I zoomed in on the details of the error message and noticed the following line:
SEVERE: Path to rj package not found. Use R_LIBS or java property
'de.walware.rj.rpkg.path' to specify the location.
So I opened an RTerm run console to check whether any of my .libPaths() locations contains the directories ‘rj’ or ‘rj.gd’. Oddly enough, they do. My first .libPaths path contains both packages. So that doesn’t seem to be the reason.
How could this be fixed?
I received prompt and helpful feedback from Open Analytics (thanks!), who informed me that the problem is due to changes in Java 8. With Java 7, Architect works fine. The next release of Architect will incorporate the changes in Java 8.
In order to get it work with Java 7, enforce the use of a specific Java Runtime, by using the -vm argument in the architect.ini file as follows:
-vm
C:\Program Files\Java\jre7\bin\javaw.exe
(mind the line break, which is required)
This is particularly useful if you have several Java versions on your system where the default Java is not suitable for use with Architect. The architect.ini file is found directly at the top level of the installation folder of Architect. You can find out where this is by looking at the Properties of the Architect shortcut on your desktop.
N.B. the -vm argument should be put before the -vmargs argument otherwise it is simply ignored!
N.B. examples of -vm specification on GNU/Linux and Mac OS X:
http://wiki.eclipse.org/Eclipse.ini#-vm_value:_Linux_Example
http://wiki.eclipse.org/Eclipse.ini#-vm_value:_Mac_OS_X_Example

Question about JRI error

I try to run my R script in Java, thus I installed JRI. and run the example, I am using Eclipse on 64 bits windows 7. part of the example code is as follows:
public static void main(String[] args) {
System.out.println("Creating Rengine (with arguments)");
Rengine re=new Rengine(args, false, null);
System.out.println("Rengine created, waiting for R");
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
However, everytime I run it. it teminated after print out "Creating Rengine (with arguments)" never successfully print out "Rengine created, waiting for R"
I do not know what is right argument to input, I have tried to add "--no-save" under the Program arguments of eclipse run configuration, but still does not help.
any suggestions? Many thanks
Ref: http://www.rforge.net/JRI/
R_HOME must be set correctly
(Windows): The directory containing
R.dll must be in your PATH
(Mac): Well, it's a Mac, so it just
works ;).
(unix): R must be compiled using
--enable-R-shlib and the directory containing libR.so must be in
LD_LIBRARY_PATH. Also libjvm.so and
other dependent Java libraries must
be on LD_LIBRARY_PATH.
JRI library must be in the current
directory or any directory listed in
java.library.path.
Alternatively you can specify its
path with -Djava.library.path=
when starting the JVM. When you use
the latter, make sure you check
java.library.path property first such
that you won't break your Java.
Depending on your system, the R
verison and other features you want
to use, you may have to set
additional settings such as
R_SHARE_DIR, R_INCLUDE_DIR and
R_DOC_DIR.
My own notes:
Installing R on Mac:
Ref: http://cran.r-project.org/mirrors.html
Ref: http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html
Downloaded MacOSX binary R-2.13.0.pkg from http://cran.csiro.au/
Installing Java Interface for R (JIR) on Mac OS X
Ref: http://www.rforge.net/JRI/
JIR is now a part of rJava.
> install.packages("rJava")
--- Please select a CRAN mirror for use in this session ---
trying URL 'http://cran.csiro.au/bin/macosx/leopard/contrib/2.13/rJava_0.8-8.tgz'
Content type 'application/x-gzip' length 769006 bytes (750 Kb)
opened URL
==================================================
downloaded 750 Kb
The downloaded packages are in
/var/folders/ZZ/ZZ7tAIJsFU8FDfPPp7H53++++TM/-Tmp-//RtmpCHz9Mh/dow
> library(rJava)
> .jinit()
> s <- .jnew("java/lang/String", "Hello World!")
> print(s)
[1] "Java-Object{Hello World!}"
Running JRI example Java with Eclipse on Mac OS X
Copied the rJava/jri/examples/rtest.java to Eclipse JRI/src/.
Copied the JRI.jar from the jri directory to the JRI/lib/ and added it to the build path.
The rtest.java compiles but it did not run as a Java application.
Apparently, it needs to be run by: ./run rtest.
After examining the "run" shell script which comes with the rJava package (inside ./jri/), I have set up these in the Eclipse run configuration:
Environnment:
R_HOME = /Library/Frameworks/R.framework/Resources
PATH=/Library/Frameworks/R.framework/Resources/bin/
In addition, the example run shell script sets up the following Environment vars:
R_INCLUDE_DIR=Library/Frameworks/R.framework/Resources/include
R_SHARE_DIR=Library/Frameworks/R.framework/Resources/share
R_DOC_DIR=Library/Frameworks/R.framework/Resources/doce
JRI_LID_PATH=Library/Frameworks/R.framework/Resources/lib:/Library/Frameworks/R.framework/Resources/bin
VM argument:
-Djava.library.path=/Library/Frameworks/R.framework/Resources/library/rJava/jri/
JRI.jar is now referenced in the build path, which is:
/Library/Frameworks/R.framework/Resources/library/rJava/jri/JRI.jar.
This automatically appears under the -cp tab in the run configuration.
Also, the run configuration requires a program argument: --save, --no-save or --vanilla.
Chances are it's not finding jri.dll or R.dll. If you see nothing, not even an exception, the JVM is crashing. Look for files like hs_pid* which should tell you which library is the culprit.
I have found this question in my own struggles with R on Windows, although on Linux it just worked.
I too found I was getting "Creating Rengine (with arguments)" but nothing further.
It was finding jri.dll and R.dll, which I was able to prove:
jri.dll - deleted it from the current directory, which generated the error:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: no jri in java.library.path
(on copying it back, make sure to take the right 32 or 64 bit version to avoid "Can't load IA 32-bit .dll on a AMD 64-bit platform" type errors)
R.dll lives under the installation directory C:\Program Files\R\R-2.15.0\bin\x64
If the PATH is set incorrectly in the run.bat file (which it was) then you get the slightly different error
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: [CURRENT DIR]\jri.dll: Can't find dependent libraries
With those two things set correctly (and no hs_pid* files being generated) I found the problem to be the lack of R_HOME in run.bat. Adding
set R_HOME=C:\Program Files\R\R-2.15.0\
fixed it, and now it all seems to work for me. I did not need to add --save, --no-save or --vanilla to the script. Also, it had 'runtest' hardcoded, so ./run.bat runtest2 will not DWYM.
Short answer: The Windows run.bat script was broken (whereas the Linux 'run' script was correct out of the box).
I got the same problem while working with rJava, Windows 7 64 bit.
And here is the solution.
Added -Djava.library.path="${env_var:PATH}" in eclipse -> Project -> Run As -> Run Configuration -> Arguments.
And make sure System.getProperty("java.library.path") is pointing to jri.dll
I spent lot of time on this issue, so feel free to ask any questions ;)
The below error can be due to two paths not set, one is r.dll not found or/and jri.dll not found. Make sure system path includes for 32 bit systems
%R_HOME%\bin;%R_HOME%\bin\i386;%R_HOME%\library\rJava\jri\i386
Also make sure install.packages("rJava") plugin is installed from R console
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: no jri in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:65)
at org.codehaus.groovy.runtime.callsite.CallSiteArray$1.run(CallSiteArray.java:62)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:62)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:159)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at com.acumetric.crux.analysis.StatisticCalculator.<init>(StatisticCalculator.groovy:15)

Resources