R for Python Developers
Move from Python 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.
Python and R side by side
The same program in Python and in R, from the lessons of this course.
Text and Output
Python print adds a newline and converts values for display. R cat concatenates text without an automatic final newline unless one is supplied. paste combines values into strings; paste0 omits its separator. Rscript runs a main file, and source loads…
Python1ready = 32print(f"Ready: {ready}")R1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")Comparisons and Recycling
Python list equality produces one Boolean from a sequence comparison. R == is vectorized and may recycle shorter operands. identical tests complete object identity of values and attributes, including storage type, while all can reduce an elementwise…
Python1a = "".join(["t", "e", "a"])2print(a == "tea")R1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")Vector Subsetting
Python lists are zero-based and accept negative indexes from the end. R positive indexes are one-based, negative indexes exclude positions, and zero selects nothing. Mixing positive and negative indexes is generally invalid except zero. Logical indexing…
Python1values = [4, 8, 12]2print(values[-1])R1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")Typed Iteration
Python comprehensions build containers with flexible result types. R lapply returns a list; sapply attempts simplification that can change shape; vapply requires a prototype describing each result. A typed empty result is easier to reason about than a shape…
Python1words = [s.upper() for s in ["a", "tea"] if len(s) > 1]2print(",".join(words))R1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")Functions and Returns
Python functions return None without an explicit result. R functions return the final evaluated expression by default, with return available for early exits. R function calls use lexical scoping and lazy argument promises, unlike Python eager argument…
Python1def is_long(text: str) -> bool:2 return len(text) > 43 4print(is_long("coffee"))R1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")String Parsing
Python split and strip operate on strings directly. R strsplit returns a list of character vectors, so extracting the first component is often necessary for one input string. trimws handles surrounding whitespace, while regex and fixed splitting are distinct…
Python1print(" tea ".strip().upper())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 Python Developers for?
For people who already write Python and want to learn R. Each lesson starts from Python 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 Python basics: variables, conditions, loops, functions and collections.
How many lessons does R for Python Developers have?
R for Python Developers contains 48 interactive lessons you can complete at your own pace.
What does R for Python 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 Python Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.