SlideShare a Scribd company logo
Idiomatic R
   for Rosetta Code
Vienna<-R Meetup II, March 2013




    Peter Kofler, ‘Code Cop’
        @codecopkofler
      www.code-cop.org

    Copyright Peter Kofler, licensed under CC-BY.
Peter Kofler
• Ph.D. (Appl. Math.)

• Java et.al. Software
  Developer for 13 years

• „fanatic about code quality“

• R “developer” since 2012
The opinions expressed here are my
own and do not necessarily represent
 those of current or past employers.
Rosetta
Code
Rosetta Code
●
    http://rosettacode.org/
●
    programming chrestomathy site
       ●
         solutions to same task
       ●
         in many different languages
       ●
         demonstrate how languages are
           similar/different
R „Easy Picks“
●
    Some basic samples not set, e.g.
       ●
           http://rosettacode.org/wiki/Include_a_file#R
       ●
           http://rosettacode.org/wiki/Element-wise_operations#R
●
    We should search for them and fix
       ●
         now you know where to go
          in your lunch break
          (instead of Facebook ;-)
       ●
           http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_R
Solve a Task
●
  before editing the Rosetta Code page
      ●
        read the task
      ●
        solve it
      ●
        check your solution
●
  add your code to web
      ●
        hit the preview button
      ●
        add descriptions to code
●
  GNU Free Documentation License
●
    http://rosettacode.org/wiki/Rosetta_Code:Solve_a_Task
<markdown>

   =={{header|R}}==

   In R most operations work on vectors and matrices:

   <lang R># create a 2-times-2 matrix
   mat <- matrix(1:4, 2, 2)</lang>

   {{out}}
   <pre>> mat <- matrix(1:4, 2, 2)
          [,1] [,2]
   [1,]      1    3
   [2,]      2    4</pre>
                                                 </markdown>
Let's See Some Code
For Review
●
    Arithmetic-geometric mean
       ●
           http://rosettacode.org/wiki/Arithmetic-geometric_mean
       ●
           http://rosettacode.org/wiki/Arithmetic-geometric_mean#R

       Is it idiomatic?
       ●


●
  Fibonacci sequence
       ●
           http://rosettacode.org/wiki/Fibonacci_sequence
       ●
           http://rosettacode.org/wiki/Fibonacci_sequence#R
       ●
           Recursive, iterative or mapping?
Work in Progress
●
    Zeckendorf number representation
●
    http://rosettacode.org/wiki/Zeckendorf_number_representation
●
  Algorithm:
      ●
        get an upper limit on Fibonacci
          numbers needed to cover number
      ●
        return the sequence as digits, sorted
          descending
      ●
        drop leading 0 and convert to String
●
  Is this nice R?
PETER KOFLER, CODE-COP.ORG                 FANATIC ABOUT CODE QUALITY




                             Help Needed
  ●   Pythagorean triples
  ●   http://rosettacode.org/wiki/Pythagorean_triples
  ● I am stuck!
  ● How to find all tripples with diameter x


     in a functional way?

  ●   Is this part of Project Euler problems?
       Oops!
Thank
 You
Peter Kofler

  @codecopkofler

www.code-cop.org
CC Images
●
    Rosetta Stone: http://www.flickr.com/photos/nrbelex/454711486/
●
    Judge Dredd: http://www.flickr.com/photos/eldave/6169431454/
●
    Matrix: http://www.flickr.com/photos/trinity-of-one/20562069/
●
    Questions: http://www.flickr.com/photos/seandreilinger/2326448445/

More Related Content

What's hot (20)

PDF
Code Quality Assurance v4 (2013)
Peter Kofler
 
PDF
Clean Readable Specifications (ETC 2016)
Peter Kofler
 
PDF
Extract Method Refactoring Workshop (2016)
Peter Kofler
 
PDF
Coding Dojo: Bank OCR Outside-In (2015)
Peter Kofler
 
PDF
Pair Programming (2015)
Peter Kofler
 
PDF
Mob Programming (2016)
Peter Kofler
 
PDF
GDCR15 in Las Palmas, Gran Canaria
Peter Kofler
 
PDF
Refactoring the Tennis Kata (2013)
Peter Kofler
 
PDF
Code Retreat Venice (2016)
Peter Kofler
 
PDF
Refactoring the Tennis Kata v2 (2016)
Peter Kofler
 
PDF
Coding Dojo: Naming with Dices (2021)
Peter Kofler
 
PDF
Brutal Coding Constraints (ITAKE 2017)
Peter Kofler
 
PDF
Coding Dojo: Adding Tests to Legacy Code (2014)
Peter Kofler
 
PDF
Coding Dojo: Asynchronous Clock-In (2016)
Peter Kofler
 
PDF
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Peter Kofler
 
PDF
Coding Dojo: Data Munging (2016)
Peter Kofler
 
PDF
JUnit Boot Camp (GeeCON 2016)
Peter Kofler
 
PDF
Coding Dojo Object Calisthenics (2016)
Peter Kofler
 
PDF
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Peter Kofler
 
PDF
Coding Dojo: Baby Steps Push Challenge (2021)
Peter Kofler
 
Code Quality Assurance v4 (2013)
Peter Kofler
 
Clean Readable Specifications (ETC 2016)
Peter Kofler
 
Extract Method Refactoring Workshop (2016)
Peter Kofler
 
Coding Dojo: Bank OCR Outside-In (2015)
Peter Kofler
 
Pair Programming (2015)
Peter Kofler
 
Mob Programming (2016)
Peter Kofler
 
GDCR15 in Las Palmas, Gran Canaria
Peter Kofler
 
Refactoring the Tennis Kata (2013)
Peter Kofler
 
Code Retreat Venice (2016)
Peter Kofler
 
Refactoring the Tennis Kata v2 (2016)
Peter Kofler
 
Coding Dojo: Naming with Dices (2021)
Peter Kofler
 
Brutal Coding Constraints (ITAKE 2017)
Peter Kofler
 
Coding Dojo: Adding Tests to Legacy Code (2014)
Peter Kofler
 
Coding Dojo: Asynchronous Clock-In (2016)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Peter Kofler
 
Coding Dojo: Data Munging (2016)
Peter Kofler
 
JUnit Boot Camp (GeeCON 2016)
Peter Kofler
 
Coding Dojo Object Calisthenics (2016)
Peter Kofler
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Peter Kofler
 
Coding Dojo: Baby Steps Push Challenge (2021)
Peter Kofler
 

Similar to Idiomatic R for Rosetta Code (2013) (20)

PDF
Matlab/R Dictionary
Marck Vaisman
 
PPTX
class.4.pptxgxdfggdxfgxfgdxbhnjgnjmjmbxg
Amar954138
 
PPT
R Programming Intro
062MayankSinghal
 
PDF
Introduction to R programming
Alberto Labarga
 
PPTX
Ggplot2 v3
Josh Doyle
 
PPTX
Introducing R
nzfauna
 
DOCX
simple programs.docx
karthikaparthasarath
 
PPT
Loops and functions in r
manikanta361
 
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
PDF
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
PPT
R tutorial for a windows environment
Yogendra Chaubey
 
KEY
R for Pirates. ESCCONF October 27, 2011
Mandi Walls
 
PDF
R Programing language Notes Unit 5 Data Viz in R
en20cs301479
 
PDF
Introduction to Data Science With R Lab Record
Lakshmi Sarvani Videla
 
PPTX
“Introduction to MATLAB & SIMULINK”
Amarjeetsingh Thakur
 
PDF
Basic operations by novi reandy sasmita
beasiswa
 
PDF
R for Pythonistas (PyData NYC 2017)
Christopher Roach
 
KEY
PyCon Philippines 2012 Keynote
Daniel Greenfeld
 
PDF
Data Analysis with R (combined slides)
Guy Lebanon
 
PDF
Helvetia
ESUG
 
Matlab/R Dictionary
Marck Vaisman
 
class.4.pptxgxdfggdxfgxfgdxbhnjgnjmjmbxg
Amar954138
 
R Programming Intro
062MayankSinghal
 
Introduction to R programming
Alberto Labarga
 
Ggplot2 v3
Josh Doyle
 
Introducing R
nzfauna
 
simple programs.docx
karthikaparthasarath
 
Loops and functions in r
manikanta361
 
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
R tutorial for a windows environment
Yogendra Chaubey
 
R for Pirates. ESCCONF October 27, 2011
Mandi Walls
 
R Programing language Notes Unit 5 Data Viz in R
en20cs301479
 
Introduction to Data Science With R Lab Record
Lakshmi Sarvani Videla
 
“Introduction to MATLAB & SIMULINK”
Amarjeetsingh Thakur
 
Basic operations by novi reandy sasmita
beasiswa
 
R for Pythonistas (PyData NYC 2017)
Christopher Roach
 
PyCon Philippines 2012 Keynote
Daniel Greenfeld
 
Data Analysis with R (combined slides)
Guy Lebanon
 
Helvetia
ESUG
 
Ad

More from Peter Kofler (10)

PDF
Writing Tests with the Unity Test Framework
Peter Kofler
 
PDF
Outside-in Test Driven Development - the London School of TDD
Peter Kofler
 
PDF
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Peter Kofler
 
PDF
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Peter Kofler
 
PDF
Deliberate Practice, New Learning Styles (2015)
Peter Kofler
 
PDF
Pragmatic Introduction to PHP Unit Testing (2015)
Peter Kofler
 
PDF
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Peter Kofler
 
PDF
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
Peter Kofler
 
PDF
Code Refactoring - Live Coding Demo (JavaDay 2014)
Peter Kofler
 
PDF
Coding Dojo: Bank OCR (2014)
Peter Kofler
 
Writing Tests with the Unity Test Framework
Peter Kofler
 
Outside-in Test Driven Development - the London School of TDD
Peter Kofler
 
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Peter Kofler
 
Deliberate Practice, New Learning Styles (2015)
Peter Kofler
 
Pragmatic Introduction to PHP Unit Testing (2015)
Peter Kofler
 
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Peter Kofler
 
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
Peter Kofler
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Peter Kofler
 
Coding Dojo: Bank OCR (2014)
Peter Kofler
 
Ad

Recently uploaded (20)

PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Productivity Management Software | Workstatus
Lovely Baghel
 
PDF
HydITEx corporation Booklet 2025 English
Георгий Феодориди
 
PPTX
Earn Agentblazer Status with Slack Community Patna.pptx
SanjeetMishra29
 
PPTX
UI5Con 2025 - Beyond UI5 Controls with the Rise of Web Components
Wouter Lemaire
 
PPTX
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
PDF
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
PDF
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
Fwdays
 
PDF
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PDF
Shuen Mei Parth Sharma Boost Productivity, Innovation and Efficiency wit...
AWS Chicago
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
Arcee AI - building and working with small language models (06/25)
Julien SIMON
 
PDF
Bitcoin+ Escalando sin concesiones - Parte 1
Fernando Paredes García
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Productivity Management Software | Workstatus
Lovely Baghel
 
HydITEx corporation Booklet 2025 English
Георгий Феодориди
 
Earn Agentblazer Status with Slack Community Patna.pptx
SanjeetMishra29
 
UI5Con 2025 - Beyond UI5 Controls with the Rise of Web Components
Wouter Lemaire
 
Simplifying End-to-End Apache CloudStack Deployment with a Web-Based Automati...
ShapeBlue
 
UiPath vs Other Automation Tools Meeting Presentation.pdf
Tracy Dixon
 
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
Fwdays
 
Upgrading to z_OS V2R4 Part 01 of 02.pdf
Flavio787771
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Shuen Mei Parth Sharma Boost Productivity, Innovation and Efficiency wit...
AWS Chicago
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Arcee AI - building and working with small language models (06/25)
Julien SIMON
 
Bitcoin+ Escalando sin concesiones - Parte 1
Fernando Paredes García
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
How Current Advanced Cyber Threats Transform Business Operation
Eryk Budi Pratama
 

Idiomatic R for Rosetta Code (2013)

  • 1. Idiomatic R for Rosetta Code Vienna<-R Meetup II, March 2013 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  • 2. Peter Kofler • Ph.D. (Appl. Math.) • Java et.al. Software Developer for 13 years • „fanatic about code quality“ • R “developer” since 2012
  • 3. The opinions expressed here are my own and do not necessarily represent those of current or past employers.
  • 5. Rosetta Code ● http://rosettacode.org/ ● programming chrestomathy site ● solutions to same task ● in many different languages ● demonstrate how languages are similar/different
  • 6. R „Easy Picks“ ● Some basic samples not set, e.g. ● http://rosettacode.org/wiki/Include_a_file#R ● http://rosettacode.org/wiki/Element-wise_operations#R ● We should search for them and fix ● now you know where to go in your lunch break (instead of Facebook ;-) ● http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_R
  • 7. Solve a Task ● before editing the Rosetta Code page ● read the task ● solve it ● check your solution ● add your code to web ● hit the preview button ● add descriptions to code ● GNU Free Documentation License ● http://rosettacode.org/wiki/Rosetta_Code:Solve_a_Task
  • 8. <markdown> =={{header|R}}== In R most operations work on vectors and matrices: <lang R># create a 2-times-2 matrix mat <- matrix(1:4, 2, 2)</lang> {{out}} <pre>> mat <- matrix(1:4, 2, 2) [,1] [,2] [1,] 1 3 [2,] 2 4</pre> </markdown>
  • 10. For Review ● Arithmetic-geometric mean ● http://rosettacode.org/wiki/Arithmetic-geometric_mean ● http://rosettacode.org/wiki/Arithmetic-geometric_mean#R Is it idiomatic? ● ● Fibonacci sequence ● http://rosettacode.org/wiki/Fibonacci_sequence ● http://rosettacode.org/wiki/Fibonacci_sequence#R ● Recursive, iterative or mapping?
  • 11. Work in Progress ● Zeckendorf number representation ● http://rosettacode.org/wiki/Zeckendorf_number_representation ● Algorithm: ● get an upper limit on Fibonacci numbers needed to cover number ● return the sequence as digits, sorted descending ● drop leading 0 and convert to String ● Is this nice R?
  • 12. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY Help Needed ● Pythagorean triples ● http://rosettacode.org/wiki/Pythagorean_triples ● I am stuck! ● How to find all tripples with diameter x in a functional way? ● Is this part of Project Euler problems? Oops!
  • 14. Peter Kofler @codecopkofler www.code-cop.org
  • 15. CC Images ● Rosetta Stone: http://www.flickr.com/photos/nrbelex/454711486/ ● Judge Dredd: http://www.flickr.com/photos/eldave/6169431454/ ● Matrix: http://www.flickr.com/photos/trinity-of-one/20562069/ ● Questions: http://www.flickr.com/photos/seandreilinger/2326448445/