R for Rust Developers
Move from Rust 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.
Rust and R side by side
The same program in Rust and in R, from the lessons of this course.
Text and Output
Rust println! formats values and adds a newline, while print! omits one. R cat needs explicit separators and a final newline; paste and paste0 build strings. Rscript runs an entry file and source evaluates supporting declarations. R print may add indexes or…
Rust1fn main() {2println!("Hi, {}", "Ada");3}R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")Comparisons and Recycling
Rust PartialEq implementations determine value equality, and vectors compare their element sequences. R == is elementwise and may recycle shorter operands. Use all for a reduced decision or identical when storage types and attributes belong to equality.…
Rust1 2fn main(){3let a=vec![2,3];let b=vec![2,3];println!("{}",a==b);4}R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")Vector Subsetting
Rust slices and vectors use zero-based usize positions, and negative integers are not end-relative indexes. For a nonempty vector, len minus one selects the last value. R positive indexes start at one, negative indexes exclude positions and zero selects…
Rust1 2fn main(){3let values=vec![4,8,12];println!("{}",values[values.len()-1]);4}R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")Typed Iteration
Rust iterator map is lazy and collect materializes a chosen container type. R lapply returns a list immediately, sapply attempts simplification and vapply checks a type-and-length prototype for each result. Choose the output shape explicitly, especially for…
Rust1 2fn main(){3let words=["a","tea"];let lengths:Vec<usize>=words.iter().map(|word|word.len()).collect();println!("{}:{}",lengths[0],lengths[1]);4}R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")Functions and Returns
Rust functions can return a final expression without a semicolon, and return provides early exit. R similarly returns the last evaluated expression, but its arguments are lazy promises rather than ordinary eager arguments. R functions use lexical environments…
Rust1fn twice(n:i32)->i32 {n*2}2fn main() {3println!("{}",twice(4));4}R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")String Parsing
Rust str.parse returns a Result, including failure for invalid integer text or values outside the selected type’s range. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Fixed separators differ from regular…
Rust1 2fn main(){3println!("{}",if "12cats".parse::<i32>().is_ok(){"valid"}else{"invalid"});4}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 Rust Developers for?
For people who already write Rust and want to learn R. Each lesson starts from Rust 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 Rust basics: variables, conditions, loops, functions and collections.
How many lessons does R for Rust Developers have?
R for Rust Developers contains 48 interactive lessons you can complete at your own pace.
What does R for Rust 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 Rust Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.