7
$\begingroup$

So it looks like I got RLink working on my Windows machine:

Needs["RLink`"]
RLinkResourcesInstall[]
RSet["myVar", 10]
10
REvaluate["{
 a <- 1;
 b <- 2;
 c <- 3;
 c(a,b,c)
}"]
{1., 2., 3.}

However if I try to install quantmod or any package for that matter, this happens:

REvaluate["install.packages(\"quantmod\")"]
REvaluate::rerr: Failed to retrieve the value for variable or piece of code install.packages("quantmod").
The following R error was encountered: Error in gzfile(file, mode) : cannot open the connection

Any help to fix this and get my packages working via RLink would be greatly appreciated.

Update: Still not working

I downloaded R version 4.1.3 from https://cran.r-project.org/ and set it to my C:\ Program Files directory.

I then ran

InstallR["RHomeLocation" -> "C:\\Program Files\\R\\R-4.1.3"]

And got this error message

InstallR::nxctlib: Warning: no JRI library found for R version 
4.1.3. Will attempt to use the library for version 4.1.2. In case 
of failure, build JRI library from within R console (happens 
automatically when installing rJava Rpackage, see RLink 
documentation for using RLink with external R distributions, for 
more details), and point InstallR[] to it by passing the directory 
containing JRI library (typically R-home- 
directory/library/rJava/jri), as a value for "NativeLibLocation" 
option.

I then installed what I believed to be rJave Rpackage from here http://www.rforge.net/rJava/files/

and then ran

InstallR["RHomeLocation" -> "C:\\Program Files\\R\\R-4.1.3", 
"NativeLibLocation" -> "C:\\Program Files\\rJava\\jri"]

and got this error message

InstallR::nonlib: The value of NativeLibLocation option should 
point to an existing directory containing a valid native JRI 
library. No valid native JRI library found at location C:\Program 
Files\rJava\jri

I never coded in Java, I barely know what Java is. Can anyone tell me the simplest way to get R fully working in Mathematica so I can run some timeseries forecasts using it.

If I go and try REvaluate["install.packages(\"quantmod\")"]

It will just evaluate indefinitely without ever resolving or posting an error message. It is the same for all packages.

Thanks

$\endgroup$
11
  • 2
    $\begingroup$ On Mac M1 Max Monterrey 12.1 installing the package results in "REvaluate::crash: Crash in low-level RLink component or in R runtime. Please reinstall RLink via InstallR". RLinkResourcesInstall[] does not work for me, and I install RLink with InstallR["RHomeLocation" -> "/Library/Frameworks/R.framework/Resources", "NativeLibLocation" -> "/Library/Frameworks/R.framework/Resources/Library/rJava/JRI"]. I have the latest version of R for ARM (4.1.3). $\endgroup$
    – Michael E2
    Commented Mar 24, 2022 at 17:09
  • 1
    $\begingroup$ Using InstallR["RHomeLocation" -> "C:\\Program Files\\R\\R-4.1.1"] on my Windows 10 machine (Mathematica 13.0.1.0) allows REvaluate["install.packages(\"quantmod\")"] to work. $\endgroup$
    – JimB
    Commented Mar 24, 2022 at 20:44
  • $\begingroup$ So I take it the key is to have R already installed, install directly and not through Mathematica only. $\endgroup$ Commented Mar 24, 2022 at 20:53
  • 1
    $\begingroup$ That would be my recommendation. $\endgroup$
    – JimB
    Commented Mar 24, 2022 at 21:07
  • $\begingroup$ @JimB is the installation as easy as just downloading it on the internet or do I need to download a separate compiler as well? $\endgroup$ Commented Mar 24, 2022 at 21:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.