Menu
CoddyTech
Course

Go for R Developers

Transfer your R experience to Go: typed values, control flow, arrays, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.

R and Go side by side

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

  1. Files and the first run

    Rscript evaluates top-level R expressions, while Go builds package main and starts at its main function. R source can define functions without a special entry point. Go files in a directory share package declarations, but each file lists its own imports.…

    R
    1cat("R console\n")
    Go
    1package main2import ("fmt")3
    4func main(){fmt.Println("Go", 3)}
  2. If and scoped names

    R braces group expressions but do not create a new lexical environment; assignments in an if branch remain in the current evaluation environment. Go permits a scoped initializer shared by the if condition and branches. Port temporary variables carefully…

    R
    1n <- nchar("go"); if(n>1) cat("long\n") else cat("short\n")
    Go
    1package main2import ("fmt")3
    4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}
  3. Arrays are values

    R atomic vectors have value-like replacement behavior: changing a second binding’s element does not change the first vector. Their length is not part of a declared static type, and replacement can coerce storage. Go fixed arrays instead have length in their…

    R
    1a <- c(3L,5L); b <- a; b[1] <- 9L; cat(paste(a[1],b[1]),"\n",sep="")
    Go
    1package main2import ("fmt")3
    4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}
  4. Typed function contracts

    R function arguments are lazily evaluated promises and can have defaults, named matching and ... arguments. Go evaluates ordinary call arguments before entering a function with its explicit static signature. Port evaluation timing deliberately when an…

    R
    1is_even <- function(n) n %% 2L==0L; cat(is_even(6L),"\n",sep="")
    Go
    1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}
  5. Struct values

    R lists can model records and ordinary replacement preserves other bindings’ values. Their field set and element types remain dynamic, unlike Go structs with declared fields. Go assignment copies struct fields, but pointers, maps and slices may still share…

    R
    1a <- list(text="old"); b <- a; b$text <- "new"; cat(paste(a$text,b$text),"\n",sep="")
    Go
    1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}
  6. Errors are returned values

    R stop signals an error condition and tryCatch can handle it; warnings and other conditions have separate behavior. Go APIs normally return error values for expected failures. Preserve ordinary rejection in the return contract rather than turning it into…

    R
    1positive <- function(n) { if(n<=0) stop("not positive"); n }; tryCatch(positive(-2),error=function(e) cat("rejected\n"))
    Go
    1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for R developers

Learn Go from another language

Frequently asked questions

Who is Go for R Developers for?

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

Do I need to know Go already?

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

How many lessons does Go for R Developers have?

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

What does Go for R Developers cover?

The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.

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

Get started