\documentclass[
paper=128mm:96mm,
fontsize=11pt,
pagesize,
parskip=half-,
]{scrartcl}
\linespread{1.12}
\usepackage{xcolor}
\definecolor{mygreen}{RGB}{44,85,17}
\definecolor{myblue}{RGB}{60,60,204}
\definecolor{mybrown}{RGB}{194,164,113}
\definecolor{myred}{RGB}{255,66,56}
\newcommand*{\mygreen}[1]{\textcolor{mygreen}{#1}}
\newcommand*{\myblue}[1]{\textcolor{myblue}{#1}}
\newcommand*{\mybrown}[1]{\textcolor{mybrown}{#1}}
\newcommand*{\myred}[1]{\textcolor{myred}{#1}}
\usepackage[
includeheadfoot,
top=3.5mm,
bottom=3.5mm,
left=5.5mm,
right=5.5mm,
headsep=6.5mm,
footskip=8.5mm
]{geometry}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{utopia}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{lastpage}
\usepackage[english]{babel}
\usepackage{microtype}
\usepackage{tocstyle}
\usepackage{ulem}
\usepackage{verbatim}
\usepackage[]{hyperref}
\hypersetup{
colorlinks = true,
urlcolor = myblue,
linkcolor = myblue,
citecolor = myblue
}
\usepackage{listings}
\usepackage{wasysym}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\setkomafont{pageheadfoot}{\normalfont\color{black}\sffamily}
\makeatletter
\renewcommand*{\@textbottom}{\vskip \z@ \@plus 1fil}
\newcommand*{\@texttop}{\vskip \z@ \@plus .5fil}
\addtolength{\parskip}{\z@\@plus .25fil}
\makeatother
\makeatletter
\newtocstyle[noonewithdot]{nodotnopagenumber}{\settocfeature{pagenumberbox}{\@gobble}}
\makeatother
\usetocstyle{nodotnopagenumber}
\AtBeginDocument{\renewcaptionname{english}{\contentsname}{\Large Outline}}
\ihead{\hspace{-2mm}\begin{tikzpicture}[remember picture,overlay]\node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=2\headheight,top color=myblue!81,bottom color=myblue]{};
\end{tikzpicture}\color{white}\runninghead}
\newlength{\footheight}
\setlength{\footheight}{8mm}
\addtokomafont{pagefoot}{\footnotesize}
\ifoot{
\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=\footheight] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=3pt,top color=myblue,bottom color=mygreen]{};
\end{tikzpicture}
\myauthor\ \raisebox{0.2mm}{$\bm{\vert}$}\ \myuni
}
\ofoot[\pagemark/\pageref{LastPage}\hspace{-2mm}]{\pagemark/\pageref{LastPage}\hspace{-2mm}}
\usepackage{titlesec}
\titlespacing{\section}{0mm}{0mm}{0mm}
\titlespacing{\subsection}{0mm}{0mm}{-1mm}
\titlespacing{\subsubsection}{0mm}{0mm}{-2mm}
\setcounter{secnumdepth}{0}
\newtheoremstyle{mythmstyle}
{0.5em}
{0.5em}
{}
{}
{\sffamily\bfseries}
{}
{\newline}
{\thmname{#1}\ \thmnote{(#3)}}
\theoremstyle{mythmstyle}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{remark}[theorem]{Remark}
\newtheorem{algorithm}[theorem]{Algorithm}
\makeatletter
\newcommand*{\mybox}[2]{
\par\noindent
\begin{tikzpicture}[mynodestyle/.style={rectangle,draw=myblue,thick,inner sep=2mm,text justified,top color=white,bottom color=white,above}]\node[mynodestyle,at={(0.5*#1+2mm+0.4pt,0)}]{
\begin{minipage}[t]{#1}
#2
\end{minipage}
};
\end{tikzpicture}
\par\vspace{-1.3em}}
\newcommand*{\mytitle}{R meets Python in the Cloud}
\def\shorttitle{R meets Python}
\newcommand*{\runninghead}{\shorttitle}
\newcommand*{\newhead}[1]{\renewcommand*{\runninghead}{\shorttitle: #1}}
\newcommand*{\myauthor}{Harald Schilly}
\newcommand*{\mydate}{2013-12-03}
\newcommand*{\myuni}{University of Vienna
\raisebox{0.2mm}{$\bm{\vert}$}\
$\text{Vienna} \leftarrow \text{R Meetup}$}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=\paperheight/2] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=\paperheight/3,top color=myblue,bottom color=myblue]{};
\end{tikzpicture}
\begin{flushright}
\vspace{0.65cm}
\color{white}\sffamily
{\bfseries\Large\mytitle\par}
\vspace{0.4cm}
\normalsize
\myauthor\par
\mydate\par
\vfill
\end{flushright}
\clearpage
\newhead{Motivation}
\section{R vs. Python}
\href{http://www.r-project.org}{\textbf{R}}
is a \uline{vertically specialized} environment for statistics.
It is based on the domain specific \textbf{S} language (mid 70-ties),
has a lot of packages for statistics and supporting functionalities.
\href{http://www.python.org}{\textbf{Python}} is a general purpose language,
designed for beginners (clear syntax, easy to start),
very popular (Class A, Tiboe Index),
excellent support for extensions and
also generally accepted in engineering and scientific areas.
Remarkably, the latest incarnation of S
(``\texttt{\~}''--formulas and \texttt{data.frame})
and the first version of Python appeared both in 1991.
\clearpage
\newhead{Common Ground}
\subsection{Common Ground}
R is primarily an REPL command-line interpreter,
which can also run scripts.
It manages its own ``world'' of objects.
In order to interface with R:
\begin{itemize}
\item{data-structures:} need to be passed in and out.
\item{functions:} need to be called from the ``outside''
in order to change R's internal state on the ``inside''.
\item{plots:} are created in R and need to be made available.
\item{speed\&reliability:} everything should happen fast and reliably.
\end{itemize}
\clearpage
\newhead{RPy2}
\section{RPy2}
There is one famous Python library to accomplish this:
\href{http://rpy.sourceforge.net/rpy2.html}{\textbf{RPy2}}
It is a Python module and it is compiled against R's C Code.
That makes it a robust low-level interface.
R's environment for variable states, the functions, operators,
libraries/packages, and other elements are
\uline{exposed as Python objects}.
Exchanging data from and to R is based on
converting basic data types, ordered lists, strings,
and most notably
\href{http://wiki.scipy.org/Tentative_NumPy_Tutorial}{\uline{NumPy Arrays}}.
\clearpage
\newhead{RPy2: Example}
\begin{lstlisting}[language=python]
# evaluate arbitrary code
>>> summary = rpy2.robjects.r("...") # .reval(...)
# a function reference
>>> summary = rpy2.robjects.r['summary']
# calling `seq` directly
>>> rpy2.robjects.r.seq(1,10)
# after activating NumPy Array conversion:
>>> xx = np.array([5,4,2.2,-1,-5.5])
>>> summary(xx)
\end{lstlisting}
\clearpage
\newhead{IPython}
\section{IPython}
\href{http://www.ipython.org}{\textbf{IPython}} is probably the most
widely used interface to Python for scientific purposes.
It's excellent for rapid prototyping, exchanging ideas and results,
and publishing: e.~g. \href{http://nbviewer.ipython.org/}{NBViewer} renders them on-line.
Relevant here: a so called
\href{http://ipython.org/ipython-doc/dev/config/extensions/rmagic.html}
{\textbf{R-``magic''-extension}} exists,
based on RPy2, which helps to conveniently talk to R.
\clearpage
\newhead{IPython: Commands}
\subsection{IPython: Commands}
\begin{itemize}
\item{\texttt{\%R}} runs a line of R code: \texttt{result = \%R ...}
\item{\texttt{\%\%R -i <invar> -o <outvar> ...}}
runs the entire cell in R while converting the given input and output variables.
\item{\texttt{\%Rpush <var>}} sends the data of a given variable to R
\item{\texttt{\%Rpull <var>}} gets the variable and Python's namespace is populated
\item{\texttt{\%Rget <var>}} is similar, only retrieves the actual data.
\end{itemize}
\clearpage
\newhead{IPython: Example}
\subsection{IPython: Example}
Simple example:
\begin{verbatim}
a <- seq(10) + 5.5
print(summary(a))
\end{verbatim}
gives
\begin{verbatim}
Min. 1st Qu. Median Mean 3rd Qu. Max.
6.50 8.75 11.00 11.00 13.25 15.50
\end{verbatim}
\mygreen{$\Rightarrow{}$ All examples shown as part of this talk are
\href{http://nbviewer.ipython.org/urls/github.com/sagemath/cloud-examples/raw/master/r/rmagic.ipynb}{\uline{here}}}
\clearpage
\newhead{Sagemath Cloud}
\section{Sagemath Cloud}
\href{https://cloud.sagemath.org}{The Sagemath Cloud} is a web-based online
environment for all sorts of computations.
It's not only running
\href{http://www.sagemath.org}{the Sage mathematical software system},
but also R, LaTeX, IPython and much more.
Just open a Linux terminal and explore its capabilities \smiley
All projects can be \textit{shared with collaborators},
edits in files are \textit{synchronized} in real-time,
and your work is \textit{continuously backed-up}.
This talk and the examples are part of the
\href{https://github.com/sagemath/cloud-examples}{Sagemath Cloud examples repository}.
\clearpage
\newhead{Links}
\section{Links}
\begin{itemize}
\item \href{http://rpy.sourceforge.net/rpy2.html}{\textbf{RPy2}}
\item \href{http://www.ipython.org}{IPython}
\begin{itemize}
\item \href{http://ipython.org/ipython-doc/dev/config/extensions/rmagic.html}{R-``magic''-extension}
\item \href{http://nbviewer.ipython.org/urls/github.com/sagemath/cloud-examples/raw/master/r/rmagic.ipynb}{IPython Rmagic example}
\item \href{http://nbviewer.ipython.org/urls/github.com/ipython/ipython/raw/master/examples/notebooks/R Magics.ipynb}{IPython Documentation Example}
\end{itemize}
\item \href{https://cloud.sagemath.org}{Sagemath Cloud}
\end{itemize}
\begin{comment}
\begin{multicols}{2}
\mygreen{Sed diam enim, sagittis nec} condimentum sit amet, ullamcorper sit amet libero. \mybrown{Aliquam vel dui orci}, a porta odio. \myred{Nullam id suscipit} ipsum. \myblue{Aenean lobortis} commodo sem, ut commodo leo gravida vitae. Pellentesque vehicula ante iaculis arcu pretium rutrum eget sit amet purus. Integer ornare nulla quis neque ultrices lobortis. Vestibulum ultrices tincidunt libero, quis commodo erat ullamcorper id.
\end{multicols}
\clearpage
\subsection{Bullet Points and Numbered Lists}
\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit
\item Aliquam blandit faucibus nisi, sit amet dapibus enim tempus eu
\end{itemize}
\begin{enumerate}
\item Nulla commodo, erat quis gravida posuere, elit lacus lobortis est, quis porttitor odio mauris at libero
\item Nam cursus est eget velit posuere pellentesque
\item Vestibulum faucibus velit a augue condimentum quis convallis nulla gravida
\end{enumerate}
\clearpage
\subsection{Verbatim}
How to include a theorem in this presentation:
\begin{verbatim}
\mybox{0.8\textwidth}{
\begin{theorem}[Murphy (1949)]
Anything that can go wrong, will go wrong.
\end{theorem}
}
\end{verbatim}
\clearpage
\section{Displaying Information}
\clearpage
\subsection{Table}
\begin{table}[h]
\centering
\begin{tabular}{l l l}
\toprule
\textbf{Treatments} & \textbf{Response 1} & \textbf{Response 2}\\
\midrule
Treatment 1 & 0.0003262 & 0.562 \\
Treatment 2 & 0.0015681 & 0.910 \\
Treatment 3 & 0.0009271 & 0.296 \\
\bottomrule
\end{tabular}
\caption{Table caption}
\end{table}
\clearpage
\subsection{Figure}
\begin{figure}[h]
\centering\includegraphics[width=0.4\linewidth]{placeholder}
\end{figure}
\clearpage
\subsection{Theorem}
The most common definition of \mygreen{Murphy's Law} is as follows.
\mybox{0.8\textwidth}{
\begin{theorem}[Murphy (1949)]
Anything that can go wrong, will go wrong.
\end{theorem}
}
\begin{proof}
A special case of this theorem is proven in the textbook.
\end{proof}
\begin{remark}
This is a remark.
\end{remark}
\begin{algorithm}
This is an algorithm.
\end{algorithm}
\clearpage
\thispagestyle{empty}
\bibliographystyle{unsrt}
\bibliography{sample}
\clearpage
\begin{comment}
\section{Citations}
An example of the \texttt{\textbackslash cite} command to cite within the presentation:
This statement requires citation \cite{Smith:2012qr}.
\clearpage
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=\paperheight/2] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=\paperheight/3,top color=mygreen,bottom color=mygreen]{};
\end{tikzpicture}
\begin{flushright}
\vspace{0.6cm}
\color{white}\sffamily
{\bfseries\LARGE Questions?\par}
\vfill
\end{flushright}
\end{comment}
\end{document}