R for Lua Developers
Move from Lua 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.
Lua and R side by side
The same program in Lua and in R, from the lessons of this course.
Text and Output
Lua print adds a newline and separates multiple values with tabs, while io.write gives explicit string output control. R cat also needs deliberate separators and an explicit final newline. paste and paste0 construct strings, and source evaluates helper…
Lua1local name="Ada";print("Hello, "..name)R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")Comparisons and Recycling
Lua tables normally compare by identity unless an applicable equality metamethod changes that behavior. R == is elementwise and may recycle shorter operands. Use all for a reduced decision or identical to include values, storage types and attributes. Missing…
Lua1local a={2,3};local b={2,3};print(a==b)R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")Vector Subsetting
Lua dense sequences conventionally start at one, but table keys can also be zero or negative without special slicing meaning. R positive indexes are one-based, zero selects nothing and negative indexes exclude positions. A Lua negative key does not translate…
Lua1local values={4,8,12};print(values[#values]);print(values[-1]==nil)R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")Typed Iteration
Lua mapping commonly loops over a dense sequence and writes results into a new table. R lapply returns a list, sapply attempts simplification and vapply checks each result against a type-and-length prototype. Choose the output shape explicitly, especially for…
Lua1local words={"a","tea"};local lengths={};for i,word in ipairs(words) do lengths[i]=#word end;print(table.concat(lengths,":"))R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")Functions and Returns
Lua functions use return to produce values and can return several values, with context controlling result adjustment. R returns its last evaluated expression by default and uses return for early exit. R arguments are lazy promises, whereas ordinary Lua…
Lua1local function twice(n)return n*2 end;print(twice(3))R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")String Parsing
Lua tonumber returns nil when complete conversion fails, while Lua patterns are different from regular expressions. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Choose fixed separators or regex syntax…
Lua1print(tonumber("12cats")==nil and "invalid" or "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 Lua Developers for?
For people who already write Lua and want to learn R. Each lesson starts from Lua 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 Lua basics: variables, conditions, loops, functions and collections.
How many lessons does R for Lua Developers have?
R for Lua Developers contains 48 interactive lessons you can complete at your own pace.
What does R for Lua 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 Lua Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.