Slide 1

Slide 1 text

R programming language Rafał Łasocha @swistak35 1 year student on II@UWr ...and a little bit about Ruby/Rails integration with R

Slide 2

Slide 2 text

R ● GNU GPL ● Functions for statistics ● Easy graphics methods (for charts) ● REPL ● Object oriented

Slide 3

Slide 3 text

Use-cases ● Recommendation engines ● Speech recognition ● Spam detection ● Data mining ● Analyse everything – ecology, human genome, trading, economy, diseases, cyclons...

Slide 4

Slide 4 text

Objects ● Many types of collections: vectors, factors, matrices, arrays, lists, dataframes, tables... ● „All R objects have a class, a type and a dimensions.” ● Typical langs use 'for' loops, in ruby we use enumerators, in R the most popular are „apply” functions ● Dataframes behave like tables in databases, they even can be queried

Slide 5

Slide 5 text

Code (in REPL) > 2 + 1 [1] 3 > library(MASS) > data(cats) > class(cats) [1] "data.frame" > names(cats) [1] "Sex" "Bwt" "Hwt" > cats$Bwt [1] 2.0 2.0 2.0 2.1 2.1 … > cats$Bwt + 1 [1] 3.0 3.0 3.0 3.1 3.1 ... > mean(cats$Bwt) [1] 2.723611 > rest = cats$Bwt - (cats$Hwt/1000) > rest [1] 1.9930 1.9926 1.9905 2.0928 2.0927 ...

Slide 6

Slide 6 text

Packages Installing packages directly using REPL: > install.packages("DBI") # database communication interface … > install.packages("RPostgreSQL") # postgresql … > install.packages("ggplot2") # another charts library ... Polish mirror R is only in Wroclaw, on UWr : )

Slide 7

Slide 7 text

R + postgresql

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Exporting charts > png("example_name.png", width = 1000, height = 600) > ggplot(...) > dev.off() R + Rails = ?

Slide 10

Slide 10 text

R

Slide 11

Slide 11 text

Rails

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

RinRuby ● 100% Ruby ● Send and receive data through TCP/IP sockets ● Pros: it works. ● Cons: pretty slow, not updated since 2011, poor documentation, only 2 datatypes available: vectors and matrix

Slide 14

Slide 14 text

RSRuby ● Pros: fast! (100-1000x RinRuby), integration with Ruby (methods and objects are objects from R) ● Cons: dependent on Ruby/R version, operating system; poor documentation, not updated since 2011

Slide 15

Slide 15 text

RServe ● 100% Ruby (client), connection through TCP/IP ● Require Rserve on server, ruby connects to it with Ruby-RServe-Client (RServe came to us from Java) ● Pros: Fast, updated (rarely, but it's better than nothing) ● Cons: Require Rserve on server, poor documentation, limited functions on Windows (who cares)

Slide 16

Slide 16 text

Rapache ● Web SERVICE (SOA SOA SOA SOA SOA...) ● Pros: Modular, up-to-date ● Cons: Requires Rapache, specific to Apache server only

Slide 17

Slide 17 text

JSON API There are also libraries to export/import to CSV, Google spreadsheets, XLS (Microsoft Excel), ODS (LibreOffice Calc), and more

Slide 18

Slide 18 text

Chart

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Rkward ● Nice, written using Qt, GUI for R ● Allows to write scripts, big database of commonly-used functions, it allows to customize chart with ease

Slide 22

Slide 22 text

Sources & useful links: http://www.r-project.org/ (site of the GNU R project) http://www.slideshare.net/sausheong/rubyand-r (London RUG) http://www.mayin.org/ajayshah/KB/R/index.html (R by example, great source of knowledge!) English & Polish Wikibooks - „Programming R” http://rseek.org/ (search for blog posts, tutorials, etc. - great way to find something abou rare topics) http://www.statystycy.pl/ (polish forum with section about R programming) http://docs.ggplot2.org (docs for ggplot2 – most popular R graphics library) http://cran.r-project.org (CRAN with R packages) http://stat.bell-labs.com/RS-DBI/doc/html/index.html (nice guide for DBI – connecting with databases) http://cran.r-project.org/manuals.html (official R tutorials & manuals, with great introduction guide – simple, but quite comprehensive, about 100 pages) http://tryr.codeschool.com (Codeschool course to „Try R”) https://github.com/virtualstaticvoid/heroku-buildpack-r (Running R on heroku) Thanks! Notice: During this presentation, I didn't used any loops in code.