Basic syntax

a = 3.2
a = "a string"
print("The variable 'a' stores:"); print(a)

a = 10; b = 5; c = 1
if (a < b){
  d = 1
}else if (a == b){
  d = 2
}else{
  d = 3
}
d
stopifnot(d==3)

sum = 0
i = 1
while(i <= 10){
  sum = sum + i
  i = i + 1
}
stopifnot(sum==55)

mySum = function(a,b){
  return(a + b)
}
x = vector(length=3, mode="numeric")

y = c(4,3,3)

stopifnot( x == c(0,0,0))

stopifnot(length(y) == 3)

x[1] = 2
x[3] = 1
stopifnot( x == c(2,0,1) )

a = 2*x + y
stopifnot( a == c(8,3,4) )

a = a - 1
stopifnot( a == c(7,2,3) )

stopifnot( (a>=7) == c(TRUE,FALSE,FALSE))
stopifnot( (a==2) == c(FALSE,TRUE,FALSE))

mask = c(TRUE,FALSE,TRUE)
stopifnot( a[mask] == c(7,3) )

indices = c(1,3)
stopifnot( a[indices] == c(7,3))

stopifnot( a[c(-1,-3)] == c(2) )

stopifnot( any(c(FALSE,TRUE,FALSE)) )
stopifnot( all(c(TRUE,TRUE,TRUE)) )
stopifnot( which(c(TRUE,FALSE,TRUE)) == c(1,3) )

b = rep(3.2, times=5)
stopifnot( b == c(3.2, 3.2, 3.2, 3.2, 3.2))

w = seq(0,3)
stopifnot(w == c(0,1,2,3))

x = seq(0,1,by=0.2)
stopifnot(x == c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0))

y = seq(0,1,length.out=3)
stopifnot( x == c(0.0, 0.5, 1.0) )

z = 1:10
stopifnot(z == seq(1,10,by=1))

sum = 0
for(i in z){
	sum = sum + i
}
stopifnot(sum == 55)

x = 1:10
f = function(a){
	a[1] = 10
}
f(x)
stopifnot(x == 1:10)