vignettes/06a-R_Developing_powerful_skills.Rmd
06a-R_Developing_powerful_skills.Rmd
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.
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.
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.
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.
data.frame
base
package – everything matrix or vector is ‘fast’
raster
- for spatially referenced matrices
sp
- equivalent of vector shapefiles in a GIS
see also sf
data.table
data.frame
type data (i.e., columns of data)data.frame
is small (<100,000 rows)SpaDES
– many functions; will be moved into a separate package soon
Rcpp
SpaDES
functions quickly, because there are fewer tutorials online for theseraster
, sp
, data.table
, Rcpp
raster
tutorials
data.table
packageFrom every data.table
user ever:
install.packages('data.table')
(at least for large tables!)
raster
and data.table
togetherThe current implementation of LandR
(based on LANDIS-II) uses a “reduced” data structure throughout
Instead of keeping rasters of everything (one can imagine that there is redundancy, i.e., 2 pixels next to each other may be identical)
We make one raster of id
and one data.table
with a column called id
Then we can have as many columns as we want of information about each of these places
Like “polygons”, but for rasters, and dynamic… can change over time
This may be useful for your own module