Menu
CoddyTech
Course

Dart for R Developers

Move from R to standalone Dart through typed functions, null safety, collections, errors and object contracts. Build a four-step parcel depot, use classes, interfaces and mixins, then port two complete R programs.

R and Dart side by side

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

  1. Output and Comments

    R builds labelled text with paste0() or sprintf(), and print() shows a value with an index prefix such as [1] and quotes around strings. Dart interpolation uses dollar-prefixed names or braces in ordinary strings, and execution begins in main rather than at…

    R
    1lane <- 32cat(paste0('lane:', lane, '\n'))
    Dart
    1void main(){final lane=3;print('lane:$lane');}
  2. Boolean Conditions

    R if accepts a single number, treating 0 as FALSE and any other value as TRUE, and stops with an error on NA. Dart conditions and logical operands require bool. R && and || short-circuit like Dart, while the vectorised & and | always evaluate both sides.

    R
    1probe <- function() {2  cat('probe\n')3  TRUE4}5if (FALSE && probe()) cat('open\n') else cat('closed\n')
    Dart
    1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}
  3. Functions and Returns

    An R function returns the value of its last evaluated expression, so return() is optional, and R declares no parameter or result types. A Dart block body returns a value only through a return statement, and a non-nullable result type requires compatible…

    R
    1is_log <- function(name) endsWith(name, '.log')2print(is_log('server.log'))
    Dart
    1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}
  4. Iterables and Laziness

    R lapply, sapply and Map are eager: they call the function on every element and return the finished result. R argument promises provide a different kind of laziness; they do not make these collection operations lazy. Dart map returns a lazy Iterable that runs…

    R
    1twice <- function(n) {2  cat(sprintf("visit:%d\n", n))3  n * 2L4}5result <- lapply(c(2L, 3L), twice)6cat("made\n")7cat(result[[1]], "\n", sep = "")
    Dart
    1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}
  5. Parsing and Validation

    R as.integer returns NA with a warning on invalid text rather than stopping, and it accepts text a strict format may reject: "4.7" becomes 4 and "1e3" becomes 1000. Dart int.tryParse returns null and int.parse throws FormatException, and both reject those…

    R
    1value <- suppressWarnings(as.integer("nope"))2if (is.na(value)) cat("invalid\n")3cat(as.integer("42"), "\n", sep = "")
    Dart
    1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}
  6. Classes and Instances

    An R S3 object can be a list with a class attribute, as in this example: fields can be added at any time with $, and generic functions dispatch on the class. Because lists are copied on modify, a method returns the changed object for the caller to reassign.…

    R
    1new_lamp <- function() structure(list(on = FALSE), class = "lamp")2toggle <- function(x) UseMethod("toggle")3toggle.lamp <- function(x) {4  x$on <- !x$on5  x6}7a <- new_lamp()8b <- new_lamp()9a <- toggle(a)10cat(sprintf("%s:%s\n", a$on, b$on))
    Dart
    1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp();a.toggle();print('${a.on}:${b.on}');}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for R developers

Learn Dart from another language

Frequently asked questions

Who is Dart for R Developers for?

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

Do I need to know Dart already?

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

How many lessons does Dart for R Developers have?

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

What does Dart for R Developers cover?

The course is organized into chapters covering: First Dart Programs, Flow and Decisions, Functions and Values, Collection Pipelines, and more.

Is Dart 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 Dart for R Developers for free

Get started