How to tell RStudio to use R version from Anaconda - r

I have installed anaconda and the conda package R on my mac os x yosemite.
When I type
which R
in my terminal, I get the following output
/Users/giovannisoldi/anaconda/bin/R
so it is actually linking to the right version. However, when I open RStudio, I can see that the old version of R located in
/Library/Frameworks/R.framework/Versions/2.15/
is still used. I tried to link to the current version of R in Anaconda, with the following command:
ln -sfhv /Users/giovannisoldi/anaconda/bin/ /Library/Frameworks/R.framework/Versions/Current
However, by doing this RStudio complains that it can't locate R.
Is there a way to solve this issue?

Here's how I did it:
which R
/Users/admin/anaconda/bin/R
In my ~/.bashrc (or your ~/.bash_profile) I put this:
export RSTUDIO_WHICH_R=/Users/admin/anaconda/bin/R
Then source ~/.bashrc
(you now have to open RStudio from the terminal) finally, you can type
rstudio
or you can, again, edit your ~/.bashrc with alias rstudio='open -a RStudio .' and now the rstudio command will open RStudio in your current dir.

Related

How to install RGui to update R version

This may be an odd question: where do I find RGui?
I want to update my R-version from 4.1.2 to 4.2. I found this website which uses RGui. However I cannot find a RGui in my Windows Start Menu and searching the web yields this.
I believe I have to install any RGui and run the installation commands, is this correct? If so, can you recommend a software?
Rgui comes with R. There is nothing extra to install to run it. You do not need RStudio in order to run Rgui. RStudio is a front end to R that is separate from Rgui and is an alternative to Rgui . Unlike Rgui, RStudio does not come with R.
To get a desktop icon, run the R installer again and make sure you have the item checked for a Desktop Icon.
To locate Rgui.exe try this from the Windows cmd line assuming R is installed in the standard location.
cd C:\Program Files\R
dir /b /s Rgui.exe
Also if Rgui is already on your path then running this from the Windows cmd line should find it.
where Rgui.exe

Cannot get IRkernel::installspec() to work, jupyter-client not visible

I am still in progress to get Jupyter-Notebook and R working together on Windows 10 machine. After solving the problem with install_github() I am now facing just another issue. I am still following the official installation guide, I am stuck at step 2:
Every time I get this error - I have tried this in R GUI and RStudio, the same:
> IRkernel::installspec()
Error in IRkernel::installspec() :
jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127.
In addition: Warning message:
In system2("jupyter", c("kernelspec", "--version"), FALSE, FALSE) :
'"jupyter"' not found
My attempts so far: It was suggested here and here, that this could be a problem with the PATH variable setting, so I have added Anaconda to the PATH enviroment. I also installed the jupyter-client via the Anaconda console. No change so far. Any ideas?
This answer is based on this by #Ryan, but since the question answered was actually about a Linux based system I put it here in a Windows question:
One way to overcome the problem - if adding PATH variables to the environment doesn't work - is the following:
If Anaconda is installed and the Jupyter-Notebook with it (should be the standard install), open up the Anaconda prompt, not the Windows command prompt or the Anaconda Navigator
Look up the executable of R (not Rgui or Rstudio), it should be somewhere like C:\Program Files\R\R-3.5.1\bin and copy the path
Paste the path into the Anaconda prompt and start R by typing R
Now execute IRkernel::installspec() once again, this time there shouldn't be an error
Now you can start an R kernel within Jupyter-Notebook
You should try to open R in the terminal, if you changed directory where R il located type:
R.exe
and then run:
IRkernel::installspec()
I was having this issue trying to run Jupyter Lab on my Ubuntu 18.04 LTS headless server running in an Azure VM.
To resolve the issued, I had to navigate to /usr/bin and open R from there. It turns out that despite my path, calling R from the terminal opened the anaconda3 version in /home/<you>/anaconda3/bin/R.
Run IRkernel::installspec() from /usr/bin/R in as sudo and it should add the kernel.
If jupyter.exe is installed under c:\python36\sripts, run
"setwd("c:/python36/scripts")" on R GUI, run "IRkernel::installspec()"
Simply create a new virtual environment for R. Either using the CLI or the anaconda Navigator (best recommended, If and if you're using Anaconda).

How to set up conda-installed R for use with RStudio?

I've been trying to set up my R using conda (eventually to use with Beaker Notebook) and I want to be able to use RStudio with my conda-installed version of R.
My method of installing R:
conda install -c r r
conda install -c r r-essentials
conda install -c r r-rserve
conda install -c r r-devtools
conda install -c r r-rcurl
conda install -c r r-RJSONIO
conda install -c r r-jpeg
conda install -c r r-png
conda install -c r r-roxygen2
conda install --channel https://conda.anaconda.org/bioconda bioconductor-edger
I ran that version of R (I only installed this version)
> version
_
platform x86_64-apple-darwin11.0.0
arch x86_64
os darwin11.0.0
system x86_64, darwin11.0.0
status
major 3
minor 3.1
year 2016
month 06
day 21
svn rev 70800
language R
version.string R version 3.3.1 (2016-06-21)
nickname Bug in Your Hair
Running R in Jupyter is kind of buggy. For example, when it outputs errors, it outputs to stdout and splits every character in the string with a linebreak. I want to use RStudio but I don't want to install another version of R.
How can I route my conda version of R into RStudio?
Here's my .bash_profile not sure if this will be useful:
$ cat ~/.bash_profile
# added by Anaconda3 4.0.0 installer
export PATH="/Users/jespinoz/anaconda/bin:$PATH"
export RSTUDIO_WHICH_R=/Users/jespinoz/anaconda/bin/R
I've been trying to follow these tutorials but I am lost. I'm really not too familiar with environment variables and such things.
(1) https://support.rstudio.com/hc/en-us/community/posts/207830688-Using-RStudio-with-conda
(2) Launch mac eclipse with environment variables set
when I looked for my R it directed me to:
$ which R
/Users/jespinoz/anaconda/bin/R
but the directions from (1) is using this path which is very confusing:
/Users/jespinoz/anaconda/lib/R/bin/R
I tried doing what this guy did and added this to my .bash_profile but it didn't work. I even made a .bashrc but it still didn't work (I sourced both after I added the lines)
export RSTUDIO_WHICH_R=/Users/jespinoz/anaconda/bin/R
How to tell RStudio to use R version from Anaconda
Unfortunately, anaconda has no tutorial for this in https://docs.continuum.io/anaconda/ide_integration
See https://anaconda.org/r/rstudio:
$ conda install -c r rstudio
Then from command line:
$ rstudio
(It is how I installed it and it works.)
So long as which R shows up a working R interpreter (which it should do if you have installed the r package from conda and activated your environment) then launching rstudio from that same environment should pick it up just fine.
For a test, on ArchLinux, I built and installed: https://aur.archlinux.org/packages/rstudio-desktop-git/
.. then force removed the R interpreter (pacman -Rdd r), then installed r from conda (conda install -c r r) and it worked fine. I then closed my terminal and opened a new one (so that the correct conda environment was not activated and successfully launched RStudio with the following command: RSTUDIO_WHICH_R=/home/ray/r_3_3_1-x64-3.5/bin/R rstudio
I think the crux is to launch RStudio from the right environment? Your ~/.bash_profile and ~/.bashrc are only sourced when you run bash. For environment variables to be set so that the your desktop environment knows about them, on Linux, you should put them in ~/.profile or else in /etc/pam.d (you may need to logout or shutdown after making those changes) and on OS X, you should check out https://apple.stackexchange.com/q/57385
Update: ADD THIS TO ~/.bash_profile !
export RSTUDIO_WHICH_R="/Users/jespinoz/anaconda/bin/R"
launchctl setenv RSTUDIO_WHICH_R $RSTUDIO_WHICH_R
Credits to #Z-Shiyi for the last line https://github.com/conda/conda/issues/3316#issuecomment-241246755
An addition to what #Ray Donnelly said above. Basically, it has to be executed from the correct environment (i.e. run it from the terminal).
You can either:
(A) Put this in your ~/.bash_profile
export RSTUDIO_WHICH_R=/Users/[yourusername]/anaconda/bin/R (if youre using conda but you could put any R path)
(B) then type this in the terminal after it's been sourced (either restart terminal or do source .bash_profile): open -a RStudio
That should work.
or you can do what I did:
(A) open up automator (sorry if you're not on a mac; this will only work on mac)
(B) use a Run Shell Script
(C) then delete cat that's already in there and put in:
export RSTUDIO_WHICH_R=/Users/[yourusername]/anaconda/bin/R
open -a RStudio
(D) Save it as something like run_rstudio.app then just run that and it should work:
Launch RStudio from Activated Conda Environment
At least for Mac OS X, I find that it is sufficient to activate the environment in a shell session, then launch RStudio.
$ conda activate my_r_env
$ /Applications/RStudio.app/Contents/MacOS/RStudio
Once in R, one can verify that values of R.home() and .libPaths() point to the environment-specific locations.
The advantage here is that you aren't fixed to whatever was last set in the environment variables, e.g., via .bash_profile. Instead, one can have many R-based environments and switch between them (or run multiple ones simultaneously) without tampering with global settings.
Suggested Alias for Convenience
Perhaps the only global setting I might recommend is to add an alias for rstudio to your .bash_profile so you don't have to type the full path every time, like
alias rstudio='/Applications/RStudio.app/Contents/MacOS/RStudio &'
which enables one to then do
$ conda activate my_r_env
$ rstudio
$
where the & enables one to continue using the shell, or close it, without affecting the RStudio instance.
Update: The Anaconda Distribution now has packages for RStudio so you should be able to use that and not have to jump through any hoops at all. You can also install it directly the Anaconda Navigator.
Making a soft link works for me:
ln -s /opt/miniconda3/envs/r-4.2/bin/R /usr/bin/R
if is up to any good (now)... conda has the package rstudioapi which brings Rstudio to your local environment, and picks up the local/default r-base installed of your active environment.
you can install it (once your environment is activated) by typing:
conda install -c conda-forge r-rstudioapi
then you just type (inside your environment): rstudio

remove anaconda R from Ubuntu

I have been using ipython notebook to run some R scripts. Now the problem is I have two R versions on my Ubuntu 14.04.
One is R.3.2.2 at /home/MYNAME/anaconda2/bin/R, another one is the R which I need for R studio,
now the problem is I want to only use R.3.3.1 for my system as I need some advanced task to be done.
I use conda uninstall r, after running this, according to the print out, a lot of R related packages is removed, if i run conda uninstall r again, it said
Fetching package metadata .......
Using Anaconda Cloud api site https://api.anaconda.org
Solving package specifications: ..........
Error: no packages found to remove from environment: /home/MyName/anaconda2
but when I run Which R again, still it is the anaconda R, if I run R in the terminal, it is still R3.2.2, anyone knows how could I remove this anaconda R version?
You probably needed to run hash -r in your session (or rehash if using zsh) to update your executables on PATH for the which command. A new terminal session would also fix the problem.
you can try conda uninstall r-base, this will remove R and all of the R-library.
The questions also implies that one cannot use anaconda R with rstudio.
On Linux you can
export RSTUDIO_WHICH_R=/home/USER/anaconda3/bin/R
and add to .profile (d/o your distro) to use rstudio with anaconda R and packages

RStudio can't find LaTeX after Mavericks update

I have been using Sweave for quite sometime on my system using RStudio.
However, I recently upgraded my Mac OS from Lion to Mavericks.
This caused several issues:
First, RStudio was not able to locate the R library, and it just wont start. I reinstalled RStudio, but still got the same issue. So I reinstalled both R and RStudio, and then RStudio started to work.
And now, RStudio is still not able to locate TeX installation, and gives me the following warning:
"No TeX installation detected. Please install TeX before compiling."
This will probably get fixed by a reinstall, but I would prefer to avoid a fresh download of TeX (~2.3G).
Any ideas on how to resolve this?
RStudio expects pdflatex to be on the system path (i.e. entering Sys.which("pdflatex") at the R console should return the path to pdflatex).
You can fix the problem by getting pdflatex back on the system path:
Find the path where pdflatex is installed on your system--likely /usr/texbin, but use find /usr -name pdflatex if you need help.
Create a file called TeX in /etc/paths.d that contains this path.
For example:
$ sudo -s "echo /usr/texbin > /etc/paths.d/TeX"
You'll need to restart to apply the changes.

Resources