Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 277 additions & 0 deletions examples/installing_R.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
{
"metadata": {
"name": "",
"signature": "sha256:a972291fa378e2f4f52778fe7a2e30b8569b51fbb6c13eade479bfb878314547"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Installating R on winpython (Version of October 2014 and after) \n",
"\n",
"#### This procedure applys for Winpython of October 2014 and after\n",
"###1 - Downloading and Installing R binary in the right place"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import os\n",
"import sys\n",
"import io"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"os.environ[\"tmp_Rdirectory\"]= \"R\" \n",
"os.environ[\"R_HOME\"] = os.environ[\"WINPYDIR\"]+ \"\\\\..\\\\tools\\\\R\\\\\" \n",
"os.environ[\"R_HOMEbin\"]=os.environ[\"R_HOME\"] + \"bin\" \n",
"# for installation we need this\n",
"os.environ[\"tmp_Rbase\"]=os.path.join(os.path.split(os.environ[\"WINPYDIR\"])[0] , 'tools','R' ) "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# downloading R-3.1.2 (55Mo, may take 2/3 minutes)\n",
"try:\n",
" import urllib.request as urllib2 # Python 3\n",
"except:\n",
" import urllib2 # Python 2\n",
"if 'amd64' in sys.version.lower():\n",
" r_comp ='/COMPONENTS=\"main,x64,translations'\n",
" r_binary=\"R-3.1.2-win.exe\"\n",
" r_url=\"http://cran.r-project.org/bin/windows/base/R-3.1.2-win.exe\"\n",
" hashes=(\"9e3c0cd6311355e0d5f8e1085b288361\", \"954499b243aef3856ca66132311dfd5e70d9f7e4\" )\n",
"else:\n",
" r_comp ='/COMPONENTS=\"main,i386,translations'\n",
" r_binary=\"R-3.1.2-win.exe\"\n",
" r_url=\"http://cran.r-project.org/bin/windows/base/R-3.1.2-win.exe\"\n",
" hashes=(\"9e3c0cd6311355e0d5f8e1085b288361\", \"954499b243aef3856ca66132311dfd5e70d9f7e4\" )\n",
" \n",
"r_installer=os.environ[\"WINPYDIR\"]+\"\\\\..\\\\tools\\\\\"+r_binary\n",
"os.environ[\"r_installer\"]=r_installer\n",
"g = urllib2.urlopen(r_url) \n",
"with io.open(r_installer, 'wb') as f:\n",
" f.write(g.read())\n",
"g.close\n",
"g = None"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"#checking it's there\n",
"!dir %r_installer%"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" Le volume dans le lecteur D s'appelle DATA\n",
" Le num\u201aro de s\u201arie du volume est 10BD-2ADB\n",
"\n",
" R\u201apertoire de D:\\result_tests\\WinPython-64bit-3.3.5.4\\tools\n",
"\n",
"02/01/2015 14:16 56\u00ff930\u00ff149 R-3.1.2-win.exe\n",
" 1 fichier(s) 56\u00ff930\u00ff149 octets\n",
" 0 R\u201ap(s) 187\u00ff075\u00ff727\u00ff360 octets libres\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# checking it's the official julia0.3 \n",
"import hashlib\n",
"def give_hash(of_file, with_this):\n",
" with io.open(r_installer, 'rb') as f:\n",
" return with_this(f.read()).hexdigest() \n",
"print (\" \"*12+\"MD5\"+\" \"*(32-12-3)+\" \"+\" \"*15+\"SHA-1\"+\" \"*(40-15-5)+\"\\n\"+\"-\"*32+\" \"+\"-\"*40)\n",
"\n",
"print (\"%s %s %s\" % (give_hash(r_installer, hashlib.md5) , give_hash(r_installer, hashlib.sha1),r_installer))\n",
"assert give_hash(r_installer, hashlib.md5) == hashes[0]\n",
"assert give_hash(r_installer, hashlib.sha1) == hashes[1]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" MD5 SHA-1 \n",
"-------------------------------- ----------------------------------------\n",
"9e3c0cd6311355e0d5f8e1085b288361 954499b243aef3856ca66132311dfd5e70d9f7e4 D:\\result_tests\\WinPython-64bit-3.3.5.4\\python-3.3.5.amd64\\..\\tools\\R-3.1.2-win.exe"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# let's install it \n",
"# If you are \"USB life style\", or multi-winpython\n",
"# ==> CLICK the OPTION \"Don't create a StartMenuFolder' <== (when it will show up)\n",
"os.environ[\"tmp_R_comp\"]=r_comp\n",
"!start cmd /C %r_installer% /DIR=%tmp_Rbase% %tmp_R_comp%\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://raw.githubusercontent.com/stonebig/winpython_afterdoc/master/examples/images/r_setup_unclick_shortcut.GIF\">"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###2 - create Ipython with Rmagic .bat launcher (needed for Winpython < 2014-12-29th)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# let's create a Ipython with \"%load_ext rmagic\" launcher \n",
"bat_text = r\"\"\"\n",
"@echo off\n",
"call %~dp0env.bat\n",
"set R_HOME=%WINPYDIR%\\..\\tools\\R\\\n",
"set R_HOMEbin=%WINPYDIR%\\..\\tools\\R\\bin\n",
"set PATH=%PATH%;%R_HOMEbin%\n",
"\n",
"Ipython notebook --matplotlib=inline\n",
"\"\"\"\n",
"ipython_with_R_launcher_bat=os.environ[\"WINPYDIR\"]+\"\\\\..\\\\scripts\\\\ipython_with_R_launcher.bat\"\n",
"if sys.version_info[0] == 3:\n",
" with io.open(ipython_with_R_launcher_bat, 'w', encoding = sys.getdefaultencoding() ) as f:\n",
" for line in bat_text.splitlines():\n",
" f.write('%s\\n' % line )\n",
"else:\n",
" with io.open(ipython_with_R_launcher_bat, 'wb' ) as f:\n",
" for line in bat_text.splitlines():\n",
" f.write('%s\\r\\n' % line.encode(sys.getdefaultencoding()) )\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###3 - Launching Ipython with R \n",
"\n",
"#### if you have a winpython release after 2014-12-29 version:\n",
" Click on your usual \"ipython notebook icon\" \n",
"\n",
"#### if you have a winpython release before 2014-12-29 version:\n",
" Click on the.bat you have just created winpython-*\\scripts\\ipython_with_R_launcher.bat \n",
" \n",
" or launch the option below which will start a new Ipython Notebook server"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Nota : this not needed for winpython versions after 2014-12-29 !\n",
"!start cmd /C %WINPYDIR%\\\\..\\\\scripts\\\\ipython_with_R_launcher.bat"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And now, you should see a IPython notebook starting next to this IPython Notebook\n",
"\n",
"Check the start of this example http://nbviewer.ipython.org/github/winpython/winpython_afterdoc/blob/master/docs/FlavorR/dplyr_pandas.ipynb \n",
"\n",
"or below 2 lines\n",
"\n",
"---------------\n",
"\n",
"%load_ext rpy2.ipython\n",
"\n",
"%R install.packages('dplyr') \n",
"\n",
"---------------\n",
"\n",
"<img src=\"https://raw.githubusercontent.com/stonebig/winpython_afterdoc/master/examples/images/r_basic_example.GIF\">"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###4 - To Un-install / Re-install R (or other trouble-shooting)\n",
"\n",
"- launch winpython**\\tools\\R\\unins000.exe\n",
"\n",
"- delete the directory winpython**\\tools\\R\n",
"\n",
"- re-install\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}