R for JavaScript Developers
Move from JavaScript 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.
JavaScript and R side by side
The same program in JavaScript and in R, from the lessons of this course.
Text and Output
JavaScript console.log writes a line, while Node process.stdout.write offers direct string output. R cat needs an explicit final newline; paste and paste0 construct strings. Rscript runs an entry file and source evaluates supporting declarations. R print may…
JavaScript1const name="Ada";console.log("Hello, "+name);R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")Comparisons and Recycling
JavaScript === compares object identity, including for Arrays, and does not recursively compare contents. R == is elementwise and may recycle shorter operands. Use all to reduce an appropriate comparison or identical to include values, storage types and…
JavaScript1const a=[2,3],b=[2,3];console.log(a===b);R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")Vector Subsetting
JavaScript Arrays have zero-based indexed elements; a negative bracket key is an ordinary property name rather than end-relative indexing. Array.at offers a separate negative-index convention. R positive indexes start at one and negative indexes exclude…
JavaScript1const values=[4,8,12];console.log(values[values.length-1]);R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")Typed Iteration
JavaScript Array.map eagerly creates an Array of callback results, which can have different types. R lapply returns a list, sapply attempts simplification and vapply checks each result against a type-and-length prototype. Choose the result shape explicitly…
JavaScript1const lengths=["a","tea"].map(word=>word.length);console.log(lengths.join(":"));R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")Functions and Returns
JavaScript block-bodied functions need return for a value; reaching the end yields undefined, while expression-bodied arrows return their expression. R returns the last evaluated expression by default and offers return for early exit. R also uses lazy…
JavaScript1function twice(n){return n*2;}console.log(twice(3));R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")String Parsing
JavaScript parseInt can accept a numeric prefix, while Number attempts whole-string conversion and may return NaN. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Fixed separators and regular expressions…
JavaScript1const text="12cats";console.log(Number.isNaN(Number(text))+":"+parseInt(text,10));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 JavaScript Developers for?
For people who already write JavaScript and want to learn R. Each lesson starts from JavaScript 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 JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does R for JavaScript Developers have?
R for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does R for JavaScript 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 JavaScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.