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.
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…
Swift1let name = "Ada"2print("Hi, \(name)")R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")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…
Swift1let a = [2, 3], b = [2, 3]2print(a == b)R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")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…
Swift1let values = [4, 8, 12]2print(values.last!)R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")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…
Swift1let lengths = ["a", "tea"].map { $0.count }2print(lengths.map(String.init).joined(separator: ":"))R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")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…
Swift1func twice(_ n: Int) -> Int { n * 2 }2print(twice(4))R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")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…
Swift1print(Int("12cats")==nil ? "invalid" : "valid")R1parts <- strsplit("tea,cake", ",", fixed=TRUE)[[1]]2cat(length(parts), "\n", sep="")
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFiles and Atomic Values
6 lessonsLogic and Iteration
6 lessonsCollections and Ownership
5 lessonsData and Transformations
4 lessonsFunctions and Closures
5 lessonsParsing and S3 Dispatch
5 lessonsObjects and Invariants
6 lessonsCollaboration and Contracts
5 lessonsProject: Basket
4 lessonsFinal Challenges
2 lessonsFrequently 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.