R programming language and Ruby/Rails integration

R programming language and Ruby/Rails integration

R programming language and Ruby/Rails integration
DRUG #38 meeting
21.01.2013

0c9087813222ecf3d5ff0014488d50e1?s=128

Rafał Łasocha

January 21, 2013
Tweet

Transcript

  1. R programming language Rafał Łasocha @swistak35 1 year student on

    II@UWr ...and a little bit about Ruby/Rails integration with R
  2. R • GNU GPL • Functions for statistics • Easy

    graphics methods (for charts) • REPL • Object oriented
  3. Use-cases • Recommendation engines • Speech recognition • Spam detection

    • Data mining • Analyse everything – ecology, human genome, trading, economy, diseases, cyclons...
  4. 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
  5. 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 ...
  6. 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 : )
  7. R + postgresql

  8. None
  9. Exporting charts > png("example_name.png", width = 1000, height = 600)

    > ggplot(...) > dev.off() R + Rails = ?
  10. R

  11. Rails

  12. None
  13. 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
  14. 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
  15. 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)
  16. Rapache • Web SERVICE (SOA SOA SOA SOA SOA...) •

    Pros: Modular, up-to-date • Cons: Requires Rapache, specific to Apache server only
  17. JSON API There are also libraries to export/import to CSV,

    Google spreadsheets, XLS (Microsoft Excel), ODS (LibreOffice Calc), and more
  18. Chart

  19. None
  20. None
  21. 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
  22. 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.