Skip to content

donasaur/rlangipythonsetup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Setting up R interpreter in Notebook


You will need to have the following installed:
- Python - R - IPython, and notebook

Download and install R here:
http://cran.r-project.org/bin

To obtain Python + IPython + notebook app (if you don't have these already), I recommend the Anaconda Python distribution package here:
http://continuum.io/downloads

Now, you will also need to install the rpy2 resource package.

Mac OS/Linux specific instructions to get rpy2:
Type the following:

pip install rpy2

If you don't have pip installed (try typing pip at the terminal to test if you have it installed), get it! It's a very useful command that can be used to install various Python packages

Windows specific instructions to get rpy2:
Go here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2
and download and install the appropriate binary executable for your system (i.e. 32-bit sys: rpy2‑2.x.x.win32‑py2.7.exe; 64-bit sys: rpy2‑2.x.x.win‑amd64‑py2.7.exe)

All Users:
After that, download the following zip here to a directory of your choice:
https://github.com/donhmai/rlangipythonsetup/archive/master.zip
Unzip the files.

Mac OS/Linux specific instructions to set up rkernel.py:
cd to the directory you unzipped the files via terminal.
Type:

  bash setup_rkernel_maclinux.sh

**Windows specific instructions to set up rkernel.py:**
Double-click on setup_rkernel_win.bat. It will prompt you for administrator access privileges. Click yes: these privileges are required to set the R_HOME and R_USER system environment variables that rpy2 needs in order to run properly. After that, follow the instructions as prompted by the command-line that opens up.

**All Users:**
If you don't see rkernel.py in the current directory anymore, that means that the script ran successfully!

To run the R Interpreter in IPython's notebook app, just type:
```shell ipython notebook --profile rkernel ```
When you create a new notebook, writing a series of R commands, such as:
    X <- c(0,1,2,3,4)
    Y <- c(3,5,4,6,7)
    XYlm = lm(Y~X)
    XYcoef = coef(XYlm)
    print(summary(XYlm))
    par(mfrow=c(2,2))
    plot(XYlm)
should result in the commands getting executed as they would in a standard R interpreter. Congrats!

Note: to run the regular Python interpreter (and not R) in notebook instead, just run:
```shell ipython notebook ```
This guide was based off Fernando Perez's "hack" to convert a Python interpreter session into a R interpreter session by prepending "%%R" prior to ea. command getting run

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published