results when running commands from an .R file
print(pi)
```
This code can be run by going back to the command prompt (hence the '>' in the next box) and typing:

```
> source("myscript.R")
```
This should result in the number *π* being printed to the console. Note that everything that follows the '#'-symbol was ignored by R.

13. Conditional statements. Add the following function to myscript.R:

```
toss <- function(){
    if (runif(1)>0.5){
        print("head")
    } else {
        print("tail")
    }
}
```
Save and run at the command prompt:

```
> source("myscript.R")
> toss()
```
14. Loops. Add the following function to myscript.R:

```
fibonnaci <- function(n){
    if (n < 3) { stop("n must be at least 3") }
    # seed the output vector with 0 and 1:
    s <- c(0,1)
    # loop through all numbers from 3 to n:
    for (i in 3:n){
        s[i] <- s[i-1] + s[i-2]
    }
    return(s)
}
```
Save and run at the command prompt to calculate the first 20 numbers in the Fibonnaci series:

```
> source("myscript.R")
> fibonnaci(20)
```
15. Arguably the greatest power of R is the availability of 10,000 *packages* that provide additional functionality. For example, the compositions package implements a number of statistical tools for compositional data analysis [21,22]. To install this package:

```
> install.packages("compositions")
```
Use the newly installed package to plot the built-in SkyeAFM dataset, which contains the Al2O3—FeO—MgO compositions of 23 aphyric lavas from the isle of Skye.

```
library(compositions) # load the package into memory
dat <- data(SkyeAFM) # load the Skye lava dataset
AFMcomp <- acomp(dat) # enforce the constant sum constraint
plot(AFMcomp) # plot as a ternary diagram
```
Note that the plot() function has been *overloaded* for compositional data.

#### **References**


c 2019 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
