knitr::opts_chunk$set(cache = FALSE, echo = TRUE, eval = FALSE)

Need for speed

R is widely seen as being 'slow' (see julia web page)

But, if you use a few specific tools, then this becomes irrelevant because of the powerful tools in various packages in R.

An aside

Pure R, when the most efficient vectorized code is used, appears to be half the speed of the most efficient C++.

See Hadley Wickham's page on Rcpp, scroll down to "Vector input, vector output"... ), noting that if it took 10 minutes to write the C++ code, it would have to be 150,000 times faster to make it worth it.

Need for speed

Spatial simulation means doing the same thing over and over and over ... so we need speed

We will show how to profile your code at the end of this section.

Predictive Ecology blog posts about R speed

"Vectorization"

This is at the core of making R fast. If you don't do this, then it is probably not useful to use R as a simulation engine.

# Instead of 
a <- vector()
for (i in 1:1000) {
  a[i] <- rnorm(1)
}

# use vectorized version, which is built into the functions
a <- rnorm(1000)

Vectors and Matrices

Spatial simulation

Key packages for spatial simulation

Key packages for spatial simulation

What we will do here

SpaDES functions

?`spades-package` # section 2 shows many functions

# e.g.,
?spread
?move
?cir
?adj
?distanceFromEachPoint

Working with spatial data

raster

sp

sf

The data.table package

From every data.table user ever:

*WOW that's fast!*


install.packages('data.table')

(at least for large tables!)

data.table tutorials

raster and data.table together

raster and data.table together

?rasterizeReduced

What does this do?

The Rcpp package

From every Rcpp user ever:

*WOW! Just wow.*


install.packages('Rcpp')


PredictiveEcology/SpaDES.Workshops documentation built on Jan. 30, 2021, 6:52 p.m.