RStudio - LD_PREOAD Issue - r

I get a RDOBC error in RStudio that does not occur when I use R on the server itself.
R -
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
library(RODBC)
conn = odbcConnect("Cloudera_HIVE64", uid="manishm", pwd="tdpass")
data = sqlQuery(conn,"SELECT * from default.test")
data
[1] test.id test.name
<0 rows> (or 0-length row.names)
RStudio -
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
library(RODBC)
conn = odbcConnect("ClouderaHIVE64", uid="manishm", pwd="tdpass")
Warning messages:
1: In odbcDriverConnect("DSN=ClouderaHIVE64;UID=manishm;PWD=tdpass") :
[RODBC] ERROR: state HY000, code 11560, message [unixODBC][Cloudera]ODBC Unable to locate SQLGetPrivateProfileString function.
2: In odbcDriverConnect("DSN=Cloudera_HIVE64;UID=manishm;PWD=tdpass") :
ODBC connection failed
I have checked the environment variables and have ensured that the below are correct for all users
ODBCINI=/opt/cloudera/hiveodbc/Setup/odbcinst.ini
LD_PRELOAD=/usr/lib64/libodbcinst.so
Any idea why this will work in R and not in RStudio with the same environment settings?

I once had a similar problem on ubuntu 12.04 that I could solve, but it was kind of hacky. For reasons I don't understand, it seems that environment variables are sometimes not passed to applications that are started by clicking on the launcher. The problem that I had concerned another package, but the symptoms were similar: a properly defined environment variable seemed to be unknown to RStudio.
From this experience, I suggest the following:
Open a linux shell and change directory to cd /usr/share/applications
Type sudo cp rstudio.desktop rstudio.desktop.bak to create a backup copy of this file which we will modify.
Edit rstudio.desktop as sudo with your favorite text editor, like sudo gedit rstudio.desktop
The second line after [Desktop Entry] probably contains something like Exec=/usr/lib/rstudio/bin/rstudio %F. Change this line so that the required environment variables are explicitly passed, e.g., Exec=sh -c 'env LD_PRELOAD=/usr/lib64/libodbcinst.so /usr/lib/rstudio/bin/rstudio %F'
Close RStudio and try to start again; possibly after rebooting.
If you experience any problem launching RStudio after these modifications, restore the previous version of the file rstudio.desktop with cd /usr/share/applications followed by cp -f rstudio.desktop.bak rstudio.desktop. This should restore the initial state. It means that your problem wasn't soved, but at least no harm should be done.
Hope this helps. Wishing you good luck...

Related

jni.h file not found

I'm ultimately trying to install the RJDBC package on a mac running R 3.3.3 and Java 12 and Mojave OS.
When trying to install RDJBC I get the following error:
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.
If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.
So then I go ahead and run R CMD javareconf in the terminal and I get the following error:
conftest.c:1:10: fatal error: 'jni.h' file not found
I've found various questions online around the same topic and have tried out suggested solutions and none have worked for me. Ity could be a combination of my OS/Java version. Would someone be willing to walk me through a fix here?
Update:
Stacktrace
WARNING: Initial Java 12 release has broken JNI support and does NOT work. Use stable Java 11 (or watch for 12u if avaiable).
ERROR: Java exception occurred during rJava bootstrap - see stderr for Java stack trace.
Exception in thread "main" java.lang.NullPointerException
at java.base/jdk.internal.reflect.Reflection.verifyMemberAccess(Reflection.java:130)
at java.base/java.lang.reflect.AccessibleObject.slowVerifyAccess(AccessibleObject.java:673)
at java.base/java.lang.reflect.AccessibleObject.verifyAccess(AccessibleObject.java:666)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:638)
at java.base/java.lang.reflect.Field.checkAccess(Field.java:1075)
at java.base/java.lang.reflect.Field.get(Field.java:416)
Error in .jcheck(silent = FALSE) :
java.lang.NullPointerException.jcall(f, "Ljava/lang/Object;", "get", .jcast(ic, "java/lang/Object"))new("jobjRef", jobj = <pointer: 0x7fd4a04ac4b8>, jclass = "java/lang/NullPointerException")
Interestingly, it seems to work when I run R through terminal, but not in Rstudio.
This will need some tweaking. In general, R, Java and rJava are not quite easy things to setup when they are supposed to work together. Make sure to go through: http://www.owsiak.org/r-java-11-and-making-sure-you-can-load-rjava/
Note that due to changes in Java 12 it is no longer possible to dynamically affect location of shared libraries via reflection - this affects rJava. I am pretty sure you won't get rJava and any other JNI based codes working properly with Java 12 in R.
Once you have your R configured, it will work as expected
> R
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
...
...
> install.packages("RJDBC")
--- Please select a CRAN mirror for use in this session ---
...
> library(RJDBC)
Loading required package: DBI
>
Update
For Java 12 try following. Inside ~/.profile add following line
export JAVA_HOME=$(/usr/libexec/java_home -v 12)
then, run
> sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME}/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar
and, inside R
> system("java -version")
java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
> library(RJDBC)
Loading required package: DBI
Loading required package: rJava
>
Of course, you still need XCode.app as it contains headers for JNI.
Update
In order to make sure all the apps are getting Java 11 instead of Java 12 (not only CLI based) you can "disable" Java 12 following way.
cd /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents
sudo mv Info.plist Info.plist~
Since now, even though you haven't removed Java 12, RStudio will pick up correct version.

Source .bashrc in Rstudio

I have just installed some Perl modules locally in Ubuntu 18.04 LTS.
When calling them using the RStudio Server like this
system("perl -MBio::TreeIO -e 1")
I get the following error
Can't locate Bio/TreeIO.pm in #INC (you may need to install the Bio::TreeIO module) (#INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base)
When I source ~/.bashrc in the terminal everything's ok.
I tried creating a ~/.Rprofile containing:
system(". ~/.bashrc")
but no good.
According to the documentation, accessed by running help(Startup) in the R shell, you should create a file .Renviron in your home directory which will be read when starting up a new R session. For example:
.Renviron
FOOBAR=/foo/bar/foo/bar
R shell
R
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
> cat(Sys.getenv("FOOBAR"), "\n")
/foo/bar/foo/bar
So just create your .Renviron file with the PERL5LIB variable set to your local perl package installation directory.

RStudio not loading RevoScaleR on Ubuntu 16.04

Long story short:
Calling rxImport() works fine in a Terminal R session but fails when using RStudio, despite using the same installation of R.
Setup:
I'd like to use RevoScaleR functions like rxImport(...) on Ubuntu. I have an installation of RStudio and R done through package manager.
I've installed MS Rclient following the instructions here.
Everything seems to work as I can run in the terminal:
/opt/microsoft/rclient/3.4.3/bin/R$ ./R
R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
...
Microsoft R Open 3.4.3
The enhanced R distribution from Microsoft
Microsoft packages Copyright (C) 2018 Microsoft
Loading Microsoft R Client packages, version 3.4.3.0097.
Microsoft R Client limits some functions to available memory.
See: https://go.microsoft.com/fwlink/?linkid=799476 for information
about additional features.
...
Using the Intel MKL for parallel mathematical computing (using 2 cores).
Default CRAN mirror snapshot taken on 2018-01-01.
See: https://mran.microsoft.com/.
> R.home()
[1] "/opt/microsoft/rclient/3.4.3/runtime/R"
> rxImport()
Error in rxImport() : 'inData' must be specified.
So the function is loaded and available by default. Now I tell the RStudio to use this installation of R by adding the following at the end of ~/.profile :
RSTUDIO_WHICH_R="/opt/microsoft/rclient/3.4.3/bin/R/R"
Error:
When I run rstudio I get a R console in the IDE saying:
> R.home()
[1] "/opt/microsoft/rclient/3.4.3/runtime/R"
> rxImport()
Error in rxImport() : could not find function "rxImport"
Possible causes
I've found some threads with people complaining about MS packages not dealing properly with ~ and working directory (i.e. on a remote server), setwd() doesn't solve my issue, though.
Do you have any ideas on how to get RevoScaleR to work with RStudio? Thanks in advance.
An answer I got from Github:
https://github.com/rstudio/rstudio/issues/2455#issuecomment-375327109
try setting
R_LIBS_SITE=/opt/microsoft/rclient/3.4.3/libraries/RServer
in
/opt/microsoft/rclient/3.4.3/runtime/R/etc/Renviron

Multiple versions of R installed - terminal launching wrong / different R from RStudio

I am attempting to compile my R package, and realized that I have multiple versions of R installed on my mac, which is giving me difficulty. When I run 'which R' from terminal, I receive this:
Home$ which R
/Users/Home/anaconda2/bin/R
Home$ R
R version 3.2.2 (2015-08-14) -- "Fire Safety"
However, when I launch RStudio from my applications folder, and type 'version' in the console, I get this:
> version
_
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 3.2
year 2016
month 10
day 31
svn rev 71607
language R
version.string R version 3.3.2 (2016-10-31)
nickname Sincere Pumpkin Patch
So I have 3.3.2 on RStudio (the version I want for compiling my package), and 3.2.2 from anaconda being launched in terminal when I type R in terminal.
How can I fix this? Do I have to change my path to find the correct version of R when I launch from terminal? How do I find the correct path?
Thanks!
I bet anaconda has just inserted its path at the front of your PATH variable and is overriding your newer 3.3.2 version at the terminal. If you want your 'RStudio' version to be the default version that pops up at your terminal when you type 'R', then you gotta modify your PATH. No biggie.
First, figure out which R version RStudio points to. Type the following into your RStudio console:
Sys.which("R")
I bet you'll see something like /usr/local/bin/R. So that's what you have to add to the front of your PATH (minus the '/R').
To confirm that anaconda has messed you up, open up your terminal and check out your PATH:
echo $PATH
You'll probably see /Users/YOURNAME/anaconda2/bin as the first entry in your PATH, and further down you'll see /usr/local/bin. We have to flip this order. There are a million ways to fix this. Here's the quick and dirty solution -- add the following to the bottom of your .bash_profile
export PATH="/usr/local/bin:$PATH"
And type R --version in your terminal to confirm that your default R has changed.
You might get fancy later with sed or awk if having two /usr/local/bin entries in your PATH annoys you (as it would me).
First go to the directory /Library/Frameworks/R.framework/Versions
Here you should see various versions of R that you have installed.
To change to say version 3.4 use the following sequence of commands in the Terminal:
cd /Library/Frameworks/R.framework/Versions
unlink Current
ln -s 3.4 Current
I highly recommend RSwitch. It's a tiny program that allows you to select from any installed R version, press one button, restart your R session and you'll be using the selected R version.

Cannot run R from terminal after upgrading to macOS Sierra

I recently updated my macbook to macOS Sierra (Version 10.12.3 (16D32)), and I am no longer able to run R directly from Terminal:
DN51ssqi:~ kjytay$ R
-bash: R: command not found
DN51ssqi:~ kjytay$ R --version
-bash: R: command not found
Opening R from the Applications folder or from RStudio works fine. Anyone experience this issue/has been able to fix it?
Here is my R version information:
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 3.2
year 2016
month 10
day 31
svn rev 71607
language R
version.string R version 3.3.2 (2016-10-31)
nickname Sincere Pumpkin Patch
This is just a guess, but I'm thinking this is probably an issue with your PATH settings, which might have been overwritten when you upgraded*. Seems worth a try at least. This is from the RStudio support pages**:
R from source (including MacPorts and Homebrew)
When R is installed from CRAN on OS X the R executable is installed at
/usr/bin/R. However, if R is installed directly from source or via a
package manager like MacPorts or Homebrew, then the R executable is
installed to either /usr/local/bin/R (Homebrew) or /opt/local/bin/R
(MacPorts). In order to support these variations, RStudio scans for
the R executable in the following sequence:
/usr/bin/R
/usr/local/bin/R
/opt/local/bin/R
If RStudio is not able to locate R by scanning these locations, it
will fall back to using whatever version of R is located at
/Library/Frameworks/R.framework/.
If RStudio is finding R OK, then you must have it at one of these locations. Make sure these locations are in your $PATH list:
In the Terminal:
echo $PATH
Will display your current PATHs list. If any of the locations in the RStudio quote are missing, you can see if that's where R is located by trying to specify that location. For example:
/usr/local/bin/R
If that works to start R, just add that location to your PATHs list:
export PATH=$PATH:/usr/local/bin
So that OSX knows where to find it!
* It's been noted elsewhere that homebrew breaks, for example, on upgrade to Sierra. Here's a blog post outlining some steps an R user might like to take after the upgrade: http://www.statsblogs.com/2017/01/26/upgrading-to-macos-sierra-nee-osx-for-r-users/
** Here's the support page where the quote is from https://support.rstudio.com/hc/en-us/articles/200486138-Using-Different-Versions-of-R

Resources