Source .bashrc in Rstudio - r

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.

Related

Install mxnet package in Rstudio Cloud

I want to install the package mxnet on Rstudio Cloud, which is the cloud version of Rstudio. I tried it first with R 3.6, then R 3.5.3, neither worked.
I tried to install from with this piece of code:
cran <- getOption("repos")
cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
cran["dmlc"] <- "https://s3-us-west-2.amazonaws.com/apache-mxnet/R/CRAN/"
options(repos = cran)
install.packages("mxnet")
I got a 404 error file not found. Then i tried downloading the .tar.gz installation file associated with LInux/R/CPU, and it also gave an error:
ERROR: cannot extract package from
‘/cloud/project/apache-mxnet-src-1.5.0-incubating.tar.gz’
Here is my session info:
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS
Thanks for your help. I need to get this package installed and running on Rstudio Cloud.
RStudio Cloud is linux based
Platform: x86_64-pc-linux-gnu (64-bit)
The snippet you use is instruction for R on Windows CPU platform. R on Linux instruction there says to build it from source which wouldn't work on the cloud. Seems like no CRAN repo currently has binaries of the linux version of the mxnet package.
RStudio Cloud gives you access to the terminal and you can even download the sources for mxnet, but to build it you need sudo which the terminal doesn't provide so building from source stops on ./install_mxnet_ubuntu_r.sh command here:
git clone --recursive https://github.com/apache/incubator-mxnet.git mxnet
cd mxnet/docs/install
./install_mxnet_ubuntu_r.sh

Loading rJava on Mac OS High Sierra

I am trying to install rJava package for running the XLConnect package.
Here are my system details;
R studio:Version 1.0.153
Mac OS High Sierra Version 10.13.1 (17B1003)
R version: 3.4.2
jdk-9.0.1
however, i get the following error:
I have already followed the following threads on this topic but they don't work for me:
trouble installing and loading rJava on mac El Capitan
rJava does not run on macOS Sierra
rJava load error in RStudio/R after "upgrading" to OSX Yosemite
A push in the right direction will be greatly appreciated !!
I used the procedure at the following website:
https://github.com/MTFA/CohortEx/wiki/Run-rJava-with-RStudio-under-OSX-10.10,-10.11-(El-Capitan)-or-10.12-(Sierra)
The main steps are:
Install Apple Java 6
Install the newest Java from Oracle
Fix JAVA_HOME to point to the new version. Terminal command: sudo R CMD javareconf
Install rJava from source. Terminal command: unset JAVA_HOME; R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'
My environment is
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
macOS High Sierra 10.13.2
I encountered this problem today and spent whole day trying to fix it. Luckily I found the solution at last. It works for me.
sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
Note:
If the get ln: /usr/local/lib/libjvm.dylib: File exists
in terminal. Then you should delete this file and run the command above again.
This worked for me on an M1 Mac:
Download jdk-19_macos-x64_bin.tar.gz from Java
Unzip the file and move it to /Library/Java/JavaVirtualMachines/ (may need to sudo su first)
Set export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk-19_macos-x64_bin/Contents/Home'
Run R CMD javareconf
#Kayle Sawyer's answer works almost perfectly, but you might need to reinstall command line tools first. Easiest way is to run the following in Terminal:
xcode-select --install
If you get an error saying command line tools are already installed, you can reinstall the package with this:
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
You might need to update the second command based on your OS version.
Answers from https://github.com/frida/frida/issues/338

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

RStudio - LD_PREOAD Issue

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...

Resources