Menu
CoddyTech
Course

R for Swift Developers

Move from Swift 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.

Swift and R side by side

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

  1. Text and Output

    Swift print normally adds a newline and accepts separator and terminator arguments. 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…

    Swift
    1let name = "Ada"2print("Hi, \(name)")
    R
    1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")
  2. Comparisons and Recycling

    Swift Array equality compares Equatable element values, while class identity uses ===. R == is elementwise and can recycle shorter operands. Use all for a reduced scalar decision or identical when storage types and attributes belong to equality. Missing…

    Swift
    1let a = [2, 3], b = [2, 3]2print(a == b)
    R
    1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")
  3. Vector Subsetting

    Swift Arrays use zero-based integer positions, and last provides an optional final element rather than a negative-index shortcut. R positive indexes start at one, zero selects nothing and negative indexes exclude positions. Do not mix positive and negative…

    Swift
    1let values = [4, 8, 12]2print(values.last!)
    R
    1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")
  4. Typed Iteration

    Swift collection map eagerly creates an Array with a common inferred result type; lazy views offer a different evaluation policy. R lapply returns a list, sapply attempts simplification and vapply checks a type-and-length prototype per result. Choose the…

    Swift
    1let lengths = ["a", "tea"].map { $0.count }2print(lengths.map(String.init).joined(separator: ":"))
    R
    1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")
  5. Functions and Returns

    Swift single-expression functions can omit return, while longer value-returning bodies usually use it explicitly. R returns the last evaluated expression by default and offers return for early exit. Ordinary R arguments are lazy promises, unlike ordinary…

    Swift
    1func twice(_ n: Int) -> Int { n * 2 }2print(twice(4))
    R
    1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")
  6. String Parsing

    Swift Int(text) returns an Optional when whole-number conversion succeeds within range. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Fixed separators and regular expressions differ. Validate the complete…

    Swift
    1print(Int("12cats")==nil ? "invalid" : "valid")
    R
    1parts <- strsplit("tea,cake", ",", fixed=TRUE)[[1]]2cat(length(parts), "\n", sep="")

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Swift developers

Learn R from another language

Frequently asked questions

Who is R for Swift Developers for?

For people who already write Swift and want to learn R. Each lesson starts from Swift 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 Swift basics: variables, conditions, loops, functions and collections.

How many lessons does R for Swift Developers have?

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

What does R for Swift 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 Swift 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 Swift Developers for free

Get started