R for Kotlin Developers
Move from Kotlin 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.
Kotlin and R side by side
The same program in Kotlin and in R, from the lessons of this course.
Text and Output
Kotlin println adds a line ending, while print gives explicit control over whether one is written. R cat needs an explicit final newline; paste and paste0 build strings. Rscript runs an entry file and source evaluates supporting declarations. R print may add…
Kotlin1 2fun main(){3println("Hi"+", Ada")4}R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")Comparisons and Recycling
Kotlin == delegates to value equality with null handling, while === checks reference identity; Lists compare elements, but Arrays need content-specific helpers. R == is elementwise and may recycle shorter operands. Use all to reduce a decision or identical to…
Kotlin1 2fun main(){3val a=listOf(2,3);val b=listOf(2,3);println(a==b)4}R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")Vector Subsetting
Kotlin Lists use zero-based positions and last() selects the final element of a nonempty list; negative indexes are not end-relative. R positive indexes start at one, negative indexes exclude positions and zero selects nothing. Do not mix positive and…
Kotlin1 2fun main(){3val values=listOf(4,8,12);println(values.last())4}R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")Typed Iteration
Kotlin collection map eagerly builds a result list, while Sequence operations can defer evaluation. R lapply immediately returns a list, sapply attempts simplification and vapply checks a type-and-length prototype per result. Choose an explicit result shape…
Kotlin1 2fun main(){3val lengths=listOf("a","tea").map{it.length};println(lengths.joinToString(":"))4}R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")Functions and Returns
Kotlin expression-bodied functions return their expression, while block-bodied value functions use explicit return. R returns its last evaluated expression by default and supports return for early exit. R also uses lazy argument promises rather than ordinary…
Kotlin1fun twice(n:Int)=n*22fun main(){3println(twice(4))4}R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")String Parsing
Kotlin toIntOrNull returns null for malformed or out-of-range integer text, and string helpers split or trim input. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Fixed separators differ from regular…
Kotlin1 2fun main(){3println(if("12cats".toIntOrNull()==null) "invalid" else "valid")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 Kotlin Developers for?
For people who already write Kotlin and want to learn R. Each lesson starts from Kotlin 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 Kotlin basics: variables, conditions, loops, functions and collections.
How many lessons does R for Kotlin Developers have?
R for Kotlin Developers contains 48 interactive lessons you can complete at your own pace.
What does R for Kotlin 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 Kotlin Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.