Menu
CoddyTech
Course

R for Go Developers

Move from Go 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.

Go and R side by side

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

  1. Text and Output

    Go fmt.Println adds a line ending, while fmt.Print and fmt.Printf give explicit formatting control. 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…

    Go
    1package main2import ("fmt")3
    4func main(){5fmt.Println("Hi"+", Ada")6}
    R
    1ready <- 32cat(paste0("Ready: ", ready), "\n", sep="")
  2. Comparisons and Recycling

    Go arrays with comparable elements can use ==, but slices cannot be compared to each other with ==. R == is elementwise and may recycle shorter operands. Use all for a reduced scalar decision, or identical to include storage types and attributes. Missing…

    Go
    1package main2import "fmt"3
    4func main(){5a:=[2]int{2,3};b:=[2]int{2,3};fmt.Println(a==b)6}
    R
    1cat(identical(1L, 1), all(c(2, 3) == c(2, 3)), "\n")
  3. Vector Subsetting

    Go slices use zero-based indexing and do not support negative indexes from the end. For a nonempty slice, len(x)-1 selects the final element. R positive indexes start at one, negative indexes exclude positions and zero selects nothing. Avoid mixing positive…

    Go
    1package main2import "fmt"3
    4func main(){5values:=[]int{4,8,12};fmt.Println(values[len(values)-1])6}
    R
    1values <- c(4, 8, 12)2cat(paste(values[-1], collapse=" "), "\n", sep="")
  4. Typed Iteration

    Go loops commonly fill explicitly typed slices, with allocation and result length chosen in advance. R lapply returns a list, sapply attempts simplification and vapply checks a supplied type-and-length prototype per result. Choosing the expected result shape…

    Go
    1package main2import "fmt"3
    4func main(){5words:=[]string{"a","tea"};lengths:=make([]int,len(words));for i,word:=range words{lengths[i]=len(word)};fmt.Printf("%d:%d\n",lengths[0],lengths[1])6}
    R
    1words <- c("a", "tea")2sizes <- vapply(words, nchar, integer(1), USE.NAMES=FALSE)3cat(paste(sizes, collapse=" "), "\n", sep="")
  5. Functions and Returns

    Go functions declare result types and use return to produce values, including multiple results when requested. R returns the last evaluated expression by default, with return for early exit. R functions use lexical scoping and lazy argument promises.…

    Go
    1package main2import ("fmt")3func twice(n int) int {return n*2}4func main(){5fmt.Println(twice(4))6}
    R
    1is_long <- function(text) nchar(text)>42cat(is_long("coffee"), "\n", sep="")
  6. String Parsing

    Go strconv parsing reports an error for invalid whole-number text, and strings helpers perform splitting and trimming. R trimws and strsplit operate on character vectors, with strsplit returning a list of token vectors. Fixed separators and regular…

    Go
    1package main2import ("fmt";"strconv")3
    4func main(){5_,err:=strconv.Atoi("12cats");fmt.Println(err==nil)6}
    R
    1parts <- strsplit("tea,cake", ",", fixed=TRUE)[[1]]2cat(length(parts), "\n", sep="")

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Go developers

Learn R from another language

Frequently asked questions

Who is R for Go Developers for?

For people who already write Go and want to learn R. Each lesson starts from Go 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 Go basics: variables, conditions, loops, functions and collections.

How many lessons does R for Go Developers have?

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

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

Get started