Menu
CoddyTech
Course

R for Ruby Developers

Move from Ruby to base R: vectors, missing values, data frames, functions, S3 dispatch, S4 validity and closure state. Build a connected multi-file basket and port a stock ledger.

Ruby and R side by side

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

  1. Text and Output

    Ruby puts writes lines, while print omits an automatic final newline. R cat needs explicit separators and a final newline; paste and paste0 construct strings. Rscript runs an entry file and source evaluates supporting declarations. R print may add indexes or…

    Ruby
    1name="Ada"; puts "Hi "+name+" !"
    R
    1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")
  2. Comparisons and Recycling

    Ruby Array == compares element sequences, while equal? tests object identity and eql? has its own equality contract. R == is elementwise and may recycle shorter operands. Use all for a reduced decision or identical to include storage types and attributes. An…

    Ruby
    1puts([1]==[1])
    R
    1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")
  3. Vector Subsetting

    Ruby Arrays use zero-based positive indexes and negative indexes from the end. R positive indexes start at one, negative indexes exclude positions and zero selects nothing. Translating -1 literally changes its meaning. Do not mix positive and negative…

    Ruby
    1values=[4,8,12];puts values[-1]
    R
    1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")
  4. Typed Iteration

    Ruby Enumerable map collects block results into an Array without requiring one shared element type. R lapply returns a list, sapply attempts simplification and vapply checks each result against a type-and-length prototype. Choose the required result shape…

    Ruby
    1lengths=["a","tea"].map{|word|word.length};puts lengths.join(":")
    R
    1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")
  5. Functions and Returns

    Ruby methods and R functions both normally return the last evaluated expression, with return available for early exit. The important difference here is evaluation: ordinary Ruby arguments are eager, while R arguments are promises evaluated when needed. R…

    Ruby
    1def hours(total);total/60;end;puts hours(125)
    R
    1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")
  6. String Parsing

    Ruby regular expressions can anchor whole input with \A and \z, and Integer(text,10) validates conversion more strictly than to_i prefix conversion. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Choose…

    Ruby
    1match=/\A[a-z]+:([0-9]+)\z/.match("tag:42");puts match[1]
    R
    1parts <- strsplit("tea,cake", ",", fixed=TRUE)[[1]]2cat(length(parts), "\n", sep="")

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Ruby developers

Learn R from another language

Frequently asked questions

Who is R for Ruby Developers for?

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

Do I need to know R already?

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

How many lessons does R for Ruby Developers have?

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

What does R for Ruby Developers cover?

The course is organized into chapters covering: Files and Atomic Values, Logic and Iteration, Collections and Ownership, Data and Transformations, and more.

Is R for Ruby 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 R for Ruby Developers for free

Get started