Using a new windows version of R in Jupyter notebooks - jupyter-notebook

I've installed R version 3.5.1 for windows and copied its contents to the R folder used by Anaconda3. However conda still identifies the current version as 3.4.3. Is there a "version id" file somewhere in the Anaconda3 folders?

Short solution
In short you need to install a the IRkernel package in the version of R you want to use with Jupyter and then make it available to Jupyter. See here.
Diagnosis
You may not be aware that you have two installations of R. To confirm this is the case in a Jupyter Notebook, type:
R.version
This should return values such as:
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.3
year 2017
month 11
day 30
svn rev 73796
language R
version.string R version 3.4.3 (2017-11-30)
nickname Kite-Eating Tree
Now open RStudio or RGui and input the same command, you should see different output (ignore any warnings):
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.0
year 2018
month 04
day 23
svn rev 74626
language R
version.string R version 3.5.0 (2018-04-23)
nickname Joy in Playing
Note the differences in the version.string and nickname variables in particular.
Now in your Jupyter notebook type:
R.home()
Which will give the output like:
"C:/Anaconda3/lib/R"
The same command in RStudio or RGui will return a different path e.g.:
"C:/R/R-35~1.0"
The above values may not match those on your machine, but if they are different to each other the following steps will allow you to use the latest R instance from Jupyter.
Longer solution
Copy the above R.home() path from Rstudio (or RGui)
Open Anaconda Prompt form the start menu
Type cd /d "C:/R/R-35~1.0" where the path is the same as the one you have copied. Hit return.
Type cd bin. Hit return
Type R.exe to launch the command line R from that directory
We now need to install the package IRkernel. This package makes the version of R callable as an Jupyter kernel. Type install.packages('IRkernel') and hit return.
Type IRkernel::installspec(name = 'ir35', displayname = 'R 3.5.0') to create the latest R kernel. Note you can change the name and display name to be whatever you wish.
Exit R and close any instances of Jupyter Notebooks you have running.
Launch Jupyter Notebook again and click to create a new notebook. You should find your kernel available by its display name in the drop down box.

Related

Emacs and R - Emacs closes when using tk_choose.dir

I'm using R scripts inside Emacs on Windows 10 Enterprise to analyze data. It works well but recently after sending a tk_choose.dir command, emacs closes (but not R ; the script keeps on running after choosing the folder).
If someone can tell me the result of the following command :
library(tcltk)
c_folder <- tk_choose.dir("c:/")
If needed, here is the output of the version command:
version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 4
minor 1.3
year 2022
month 03
day 10
svn rev 81868
language R
version.string R version 4.1.3 (2022-03-10)
nickname One Push-Up
Thanks in advance for your help,
Newb'R

RStudio empty at start

Seemingly out of nowhere, RStudio fails to start properly on my machine, creating a white small window, but nothing else.
I followed the advice here and here, but the problem persists. I reinstalled both R and RStudio to the latest version, tried to run in admin mode but nothing would help. Running version in R returns
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 6.0
year 2019
month 04
day 26
svn rev 76424
language R
version.string R version 3.6.0 (2019-04-26)
nickname Planting of a Tree
When I pres crtl while RStudio is starting it does ask me which R distribution to run, and the path which is stated there indeed exists and points to the R distribution which works just fine when you execute it directly.
Next, in C:\Users\myusername\Documents an empty RHISTORY file and a folder R containing a win-library folder which contains an empty folder called 3.5 (or 3.6 if I run it on R 3.6) gets created every I launch and close RStudio. Deleting these files does not help.
Finally, after installing an older RStudio version (1.0.153) it works!

R .libPaths() different in RStudio and in terminal - how to update on terminal

I'm not sure if this question has been asked before, but I didn't see anything come up at first glance. I am struggling with R library paths when trying to run an R script from the console using:
Rscript myfile.R
The libraries loaded in myfile.R are not loading up correctly. In RStudio, my library path is:
# run from console in RStudio
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library"
> version
_
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 4.1
year 2017
month 06
day 30
svn rev 72865
language R
version.string R version 3.4.1 (2017-06-30)
nickname Single Candle
However, when I check the library path of R from the command line like so, I receive the following wrong path:
Rscript -e 'print(.libPaths())'
[1] "/Users/Home/anaconda2/lib/R/library"
Rscript -e 'print(version)'
_
platform x86_64-apple-darwin11.4.2
arch x86_64
os darwin11.4.2
system x86_64, darwin11.4.2
status
major 3
minor 2.2
year 2015
month 08
day 14
svn rev 69053
language R
version.string R version 3.2.2 (2015-08-14)
nickname Fire Safety
The RStudio path returned is actually not showing the prefix, which is actually:
/Users/Home/Library/Frameworks/R.framework/Versions/3.4/Resources/library
So my question is, how do I change the wrong path (run in terminal) to the right path (run in RStudio) for my R libraries with .libPaths() ?
Thanks!

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