Menu
CoddyTech
Course

Lua for R Developers

Transfer R skills to Lua through real multi-file programs: truth rules, tables, functions, modules, errors and metatable objects. Build a stock ledger and port two R reference programs.

R and Lua side by side

The same program in R and in Lua, from the lessons of this course.

  1. Print and Comment

    R cat emits exact text with configurable separators, while print adds inspection formatting. Lua print separates multiple arguments with tabs and ends the line. Assemble one string with .. for controlled spacing instead of copying paste or paste0 syntax. R…

    R
    1cat(paste0("Hi",", Ada"),"\n",sep="")
    Lua
    1print("Hi" .. ", Ada")
  2. NULL and Missing Fields

    R NULL represents no object or an absent component, while NA is missing data inside a vector. A list can contain NULL when constructed that way, but assigning NULL through [[ removes the component. Lua nil always removes a table association when assigned.…

    R
    1record <- list(x=NULL); cat("x" %in% names(record),"\n",sep="")
    Lua
    1local d = {x = nil}2print(d.x == nil)
  3. Ranges to Numeric for

    R colon sequences include endpoints and can descend, while seq_len and seq_along safely handle empty inputs. Lua numeric for includes its limit but requires an explicit negative step to descend. Its default step is positive. Translate the visited values and…

    R
    1total <- 0; for(i in 1:3) total <- total+i; cat(total,"\n",sep="")
    Lua
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. Functions and Returns

    R functions are values and arguments are normally lazy promises; an omitted required argument fails when its value is needed. Lua function arguments are evaluated before the call and missing positions become nil. Extra Lua arguments may be ignored. Document…

    R
    1twice <- function(x) x*2; cat(twice(4),"\n",sep="")
    Lua
    1local function twice(x) return x * 2 end2print(twice(4))
  5. Lists as Dense Tables

    R negative subscripts exclude positions and produce a selected vector, while ordinary assignment preserves value semantics. Lua table.remove mutates a dense sequence and shifts later keys. Assigning nil to a middle key leaves a hole instead. Choose whether…

    R
    1values <- c("a","b","c"); values <- values[-2]; cat(paste(values,collapse=","),"\n",sep="")
    Lua
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. Sorting and Comparators

    R sort returns an ordered vector, with missing-value policies controlled by arguments. Lua table.sort mutates a dense table and expects a strict Boolean ordering. Copy before sorting if the caller needs its original sequence, and decide missing-value handling…

    R
    1a <- c(3,1,2); b <- sort(a); cat(b[1],"\n",sep="")
    Lua
    1local a={3,1,2}2table.sort(a)3print(a[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final R Ports

2 lessons

More courses for R developers

Learn Lua from another language

Frequently asked questions

Who is Lua for R Developers for?

For people who already write R and want to learn Lua. Each lesson starts from R you know and shows how Lua does the same thing, so you skip the beginner basics.

Do I need to know Lua already?

No. The course starts with your first Lua program. You need R basics: variables, conditions, loops, functions and collections.

How many lessons does Lua for R Developers have?

Lua for R Developers contains 48 interactive lessons you can complete at your own pace.

What does Lua for R Developers cover?

The course is organized into chapters covering: First Lua Programs, Values and Decisions, Iteration and Flow, Functions and Closures, and more.

Is Lua 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.

Coddy programming languages illustration

Start Lua for R Developers for free

Get started