Compiling R from source: RStudio doesn't find the libraries if started directly - r

I have compiled R 4.1.0 from source against the Intel MKL.
I have put:
source /opt/intel/oneapi/mkl/latest/env/vars.sh intel64
in ~/.bashrc.
If I open a .R file with RStudio, no problem.
But if I open RStudio directly, it is unable to start R correctly, giving me the error:
/usr/lib/rstudio/bin/rsession: error while loading shared libraries: libmkl_gf_lp64.so.1: cannot open shared object file: No such file or directory
Why is that? Doesn't RStudio run ~/.bashrc when started directly?
I am running Fedora 34 Workstation.

When shared libraries are stored in "non-standard locations" we have to tell the dynamic linker about it. That is sometimes done in the calling script (often the case with bundled software, e.g. when you download RStudio which ships with a fair number of local builds of shared libraries) but a more general solution is to tell ldconfig via its configuration.
Older systems used a line per directory in /etc/ld.so.conf. Newer systems generalize this (like many other configurations) with a directory containing small files with entries. So you can create a file named, say, /etc/ld.so.conf.d/local-mkl.conf, and place the directory path in there. If you then run sudo ldconfig all applications will know about it -- including R and RStudio calling R.

Related

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.

R Packrat Fails to load private library

I have developed a solution using R and want to transfer it to the production server (CentOS 7) which has no Internet connection to install packages. To facilitate installation of packages, I used packrat to bundle the packages I used in my R script to the project.
Using packrat::bundle(), I have created a tar file of the project and moved the file to the server and untar the zip file.
According to a post in Blogger, once I open the project, When R is started from that directory, Packrat will do its magic and make sure the software environment is the same as on the source machine.
However, when I open the project in Server (using R-Studio Server 0.99), nothing happens and it throws error of unknown packages.
When manually execute the "packarat/init.R" file below error is thrown
Error in ensurePackageSymlink(source, target) :
Target '/home/R_Projects/prjName/packrat/lib-R/base' already exists and is not a symlink
Well, I found the problem and solve it. The symlink error is related to centOS (it is not related to R). I just simply removed all the folders inside the
/home/R_Projects/prjName/packrat/lib-R
Because these folder exist, the packrat is unable to create symlink with the same name inside the lib-R folder. If I remove them, it will create a link (shortcut) to the actual folder where the r package is located.
Hope it helps future readers.

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

Install packages and libraries in a local directory on server

I have accession to universities server: Red Hat Enterprise Linux release 6.2.
My work is to test various scientific analysis programs.
I have no problem untar'ing and running them in my local directory. But most of them have lots of dependencies (perl libraries, RE2, GNU SL, glibc.i686 ) - whenever I try to install those dependencies I come up with the permission problem.
All of those packages require root to install.
Is there a way how can I install various different packages only in my local directory without asking root to install them system wide?
Yes, but the procedure varies per package. Many modern Unix packages have a configure script that you must run, which takes a --prefix option + argument specifying where the package should be installed. A directory such as $HOME/pkg would be a good options for these. Other configuration/building/installation scripts have similar options.
When building a package with dependencies, make sure you have $HOME/pkg/bin in your PATH, $HOME/pkg/lib in your LD_LIBRARY_PATH and pass -I$HOME/pkg/include and -L$HOME/pkg/lib to the compiler and linker, respectively. E.g., put the following in your shell startup file (.bashrc for Bash):
PATH=$HOME/pkg/bin:$PATH
CFLAGS=-I$HOME/pkg/include
LDFLAGS=-L$HOME/pkg/lib
LD_LIBRARY_PATH=$HOME/pkg/lib
(You shouldn't have to install glibc, ever.)

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