Vector

Row vector, 1 × n-matrix

x <- 1:3
x
## [1] 1 2 3
x = [1 2 3];
x
## 1×3 Array{Int64,2}:
##  1  2  3

Column vector, m × 1-matrix

x <- t(1:3)
x
##      [,1] [,2] [,3]
## [1,]    1    2    3
x = [1 2 3]';
x
## 3×1 Array{Int64,2}:
##  1
##  2
##  3

Sequence Generation

x <- seq(5, 1, by=-2)
x
## [1] 5 3 1
x = collect(5:-2:1)
## 3-element Array{Int64,1}:
##  5
##  3
##  1
x
## 3-element Array{Int64,1}:
##  5
##  3
##  1

Access to each element

x <- 1:3
print(x[1])
## [1] 1
x[length(x)]
## [1] 3
x = [1 2 3];
x[1]
## 1
x[end]
## 3

String

x <- "Hello, R"
x
## [1] "Hello, R"
x = "Hello, Julia";
x
## "Hello, Julia"

Concatenate

x <- paste("Hello,", "R")
x
## [1] "Hello, R"
x = "Hello," * "julia";
x = string("Hello,", "julia"); 
## "Hello,julia"
x
## "Hello,julia"

Replicate

x <- paste(rep('a', 3), collapse='')
x
## [1] "aaa"
x = repeat("a", 3);
x = 'a'^3;
x
## "aaa"

Length

x <- "abcde"
stringr::str_length(x)
## [1] 5
x = "abcde";
length(x)
## 5

contain/detect

stringr::str_detect("Hello, world.", "world")
## [1] TRUE
contains("Hello, world.", "world")
## true

collapse into a single string/join

x <- c("apples", "bananas", "pineapples")
paste(x, collapse = ", ")
## [1] "apples, bananas, pineapples"
x = ["apples", "bananas", "pineapples"];
join(x, ", ")
## "apples, bananas, pineapples"

Format and interpolate a string

x <- "Hello, world"
glue::glue("{x}")
## Hello, world
x = "Hello, world";
"$x"
## "Hello, world"

Function

f <- function(x){x+1}
f(1)
## [1] 2
function f(x)
  x + 1
end;
f(1)
## 2
f(x) = x + 1;
f(1)
## 2

Anonymous function

(function(x){x+1})(1)
## [1] 2
(x -> x + 1)(1)
## 2

Show function content

f <- function(x){
  x + 1
}
f
## function(x){
##   x + 1
## }
function f(x)
  x + 1
end;
# less(f, (Number,)) not in REPL environment
# See https://stackoverflow.com/a/26226605/3926333
code_typed(f, (Number,))
## 1-element Array{Any,1}:
##  CodeInfo(:(begin 
##         return x + 1
##     end))=>Any

Types

x <- 1
class(x)
## [1] "numeric"
x = 1;
typeof(x)
## Int64

Dealing with NA (missing)

x <- c(1,2,NA,5)
sum(x, na.rm = TRUE)
## [1] 8
# not yet in v0.6.2
#x = [1, 2, missing, 5];
#sum(skipmissing(x))

Set and get working directory

setwd("C:\\temp")
cd("C:\\temp")
getwd()
## [1] "C:/temp"
pwd()
## "C:\\temp"