Menu
CoddyTech
Course

Ruby for R Developers

Move from R to Ruby through 48 multi-file tasks covering flow, blocks, collections, errors, classes, modules and inheritance. Build a lending desk and port two complete source programs.

R and Ruby side by side

The same program in R and in Ruby, from the lessons of this course.

  1. Output and Comments

    R cat writes values without an automatic final newline, while print can add indexes and quotes. Ruby puts adds a newline to ordinary text and print does not. Both languages use a hash sign for comments outside strings. R source evaluates a file in a selected…

    R
    1cat(paste0("Hi",", Ada"),"\n",sep="")
    Ruby
    1print "oak!"2# A real comment3puts "#seed"
  2. Conditional Values

    R if and Ruby if can both supply a selected branch value. R needs a scalar nonmissing condition, while Ruby uses truthiness with only false and nil falsey. Ruby uses elsif for another branch and closes the construct with end. An unselected branch is not…

    R
    1wet <- FALSE2label <- if(wet) "rain" else "sun"3cat(label,"\n",sep="")
    Ruby
    1wet = false2icon = if wet3  "umbrella"4else5  "sun"6end7puts icon
  3. Arrays and Indexing

    R positive indexes start at one and negative indexes exclude positions, while Ruby indexes start at zero and negative indexes count from the end. Out-of-range R atomic selection can yield NA; Ruby ordinary missing array reads yield nil. Lists have additional…

    R
    1values <- c(4,8)2cat(tail(values,1),"\n",sep="")3cat(if(is.na(values[10])) "missing" else values[10],"\n",sep="")
    Ruby
    1values = [4, 8]2puts values[-1]3puts(values[9].nil? ? "missing" : values[9])
  4. Mutation and Aliases

    R vector and list replacement has value semantics, commonly implemented by copy-on-modify, while environments remain shared reference objects. Ruby assignment shares a mutable object, so reverse! is visible through every alias. Ruby reverse creates another…

    R
    1a <- c(1); b <- a; b[1] <- 9; cat(a[1],"\n",sep="")
    Ruby
    1values = [1, 2, 3]2alias_values = values3values.reverse!4puts alias_values.join(" ")
  5. Modules as Namespaces

    R source evaluates expressions in a chosen environment, and functions or environments can provide a namespace-like boundary. Ruby require_relative loads a neighboring file, while a declared module organizes constants and methods. A filename does not create a…

    R
    1bracket <- function(text) paste0("[",text,"]"); cat(bracket("ready"),"\n",sep="")
    Ruby
    1module TextTools2  def self.shout(text)3    text.upcase4  end5end6puts TextTools.shout("elm")
  6. Composing Objects

    R lists can retain function collaborators, and environments can provide shared mutable collaborators. Ruby instance variables retain object references without cloning them. Delegation supplies behavior without a superclass relationship. R promises can delay…

    R
    1policy <- function(n) n*2; order <- list(policy=policy); total <- function(x) x$policy(3);cat(total(order),"\n",sep="")
    Ruby
    1class Lens2  def label; "wide"; end3end4class Camera5  def initialize(lens); @lens = lens; end6  def label; @lens.label; end7end8puts Camera.new(Lens.new).label

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for R developers

Learn Ruby from another language

Frequently asked questions

Who is Ruby for R Developers for?

For people who already write R and want to learn Ruby. Each lesson starts from R you know and shows how Ruby does the same thing, so you skip the beginner basics.

Do I need to know Ruby already?

No. The course starts with your first Ruby program. You need R basics: variables, conditions, loops, functions and collections.

How many lessons does Ruby for R Developers have?

Ruby for R Developers contains 48 interactive lessons you can complete at your own pace.

What does Ruby for R Developers cover?

The course is organized into chapters covering: Start with Ruby, Flow and Methods, Collections and Blocks, Mutation and Errors, and more.

Is Ruby for R Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Ruby for R Developers for free

Get started