Kotlin for R Developers
Move from R to Kotlin through null safety, collection ownership, functions, properties and object contracts. Compare vectors, environments and closures, build an order processor, and port a stock ledger.
R and Kotlin side by side
The same program in R and in Kotlin, from the lessons of this course.
Strings and Templates
R cat emits values with configurable separators and needs an explicit newline; print adds display formatting. Kotlin string templates assemble text and println appends a newline. Interpolate a name or braced expression inside the string, and choose exact…
R1name <- "Ada"; cat(paste0("Hi ",name," !"),"\n",sep="")Kotlin1fun main(){2val ready=33println("Ready: $ready")4}Equality and Identity
R == compares elementwise and can return a logical vector or NA, while identical performs a stricter whole-object comparison. Kotlin == invokes null-safe equals and === tests identity. Strings use content equality, ordinary classes default to identity unless…
R1a <- "ab";b <- paste0("a","b");cat(a==b,"\n",sep="")Kotlin1fun main(){2val a=String(charArrayOf('t','e','a'))3val b=String(charArrayOf('t','e','a'))4println(a==b)5}Arrays and IntArray
R vectors use one-based indexing, negative subscripts exclude elements, and replacement may extend a vector. Kotlin arrays have fixed size and checked zero-based indexes. IntArray stores primitive integer elements on the JVM. Use last or lastIndex for the…
R1values <- c(2,4,6);cat(values[length(values)],"\n",sep="")Kotlin1fun main(){2val a=intArrayOf(4,8,12)3println(a.last())4}While, Break, and Continue
R next skips the rest of an iteration and break exits the loop. Kotlin spells the skip operation continue and requires Boolean conditions. Update a manual index before any continuing path and test a stop marker before processing it. Keep loop termination…
R1n <- 3;while(n>1) n <- n-1;cat(n,"\n",sep="")Kotlin1fun main(){2val kept=mutableListOf<String>()3for(word in listOf("tea","","STOP","coffee")){if(word=="STOP")break;if(word.isEmpty())continue;kept.add(word)}4println(kept.joinToString(","))5}Top-level Functions
R functions are values and normally evaluate arguments lazily through promises. Kotlin top-level functions have typed parameters and evaluate ordinary call arguments before entering the function. A non-Unit block body must return a result explicitly. Return…
R1hours <- function(total) total %/% 60;cat(hours(125),"\n",sep="")Kotlin1fun isLong(text:String):Boolean = text.length>42fun main(){3println(isLong("coffee"))4}Input and String Formatting
R readLines reads from connections and cat can emit exact text without print’s annotations. Kotlin readlnOrNull returns null at EOF, and toInt requires a complete valid integer string. The task driver owns console I/O, so helpers return their results. Keep…
R1cents <- 305;cat(sprintf("tea: %d.%02d",as.integer(cents %/% 100),as.integer(cents %% 100)),"\n",sep="")Kotlin1fun main(){2println(" tea ".trim().uppercase(java.util.Locale.ROOT))3}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsStarting Kotlin
6 lessonsValues and Decisions
5 lessonsCollections and Ownership
5 lessonsIteration and Transformations
5 lessonsFunctions and Callbacks
5 lessonsInput, Errors, and Files
5 lessonsClasses and State
6 lessonsComposition and Value Types
5 lessonsProject: Order Processing
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is Kotlin for R Developers for?
For people who already write R and want to learn Kotlin. Each lesson starts from R you know and shows how Kotlin does the same thing, so you skip the beginner basics.
Do I need to know Kotlin already?
No. The course starts with your first Kotlin program. You need R basics: variables, conditions, loops, functions and collections.
How many lessons does Kotlin for R Developers have?
Kotlin for R Developers contains 48 interactive lessons you can complete at your own pace.
What does Kotlin for R Developers cover?
The course is organized into chapters covering: Starting Kotlin, Values and Decisions, Collections and Ownership, Iteration and Transformations, and more.
Is Kotlin for R Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.