fdschneider / caspr

Cellular Automata for Spatial Pressure in R
MIT License
4 stars 0 forks source link

wrapper for spatial indicators package #3

Closed fdschneider closed 9 years ago

fdschneider commented 9 years ago

link function to spatial indicators package

fdschneider commented 9 years ago

@guttal @ssumithra @SabihaMajumder

The spatial_warnings repository is not a valid R package. It rather is a set of R functions that have to be downloaded and sourced. It is not straightforward to call it as a dependency and use it within our package. I see two options:

guttal commented 9 years ago

Good point -- yes, spatial_ews is just a set of functions. Pros and cons of each of those options is very clear. Option (B) is ideal, although fixing that package is not quite the priority right now. Is it sufficiently easy to convert the existing set of functions to a package in R? If you could give pointers, I will discuss with Sabiha or sumithra to see if they would have time to do it.

fdschneider commented 9 years ago

It is quite easy to wrap an R package from that. The online book by Hadley Wickham is an excellent introduction using RStudio. But basically you only need to

  1. move all relevant R files into an R subdirectory
  2. add a DESCRIPTION file (see caspr package). specify the dependencies on other packages
  3. add a NAMESPACE file (see caspr)
  4. add a README.md containing at least some instructions on how to install and use the package.
  5. remove all the source() and require()calls within the functions. All files in subdirectory R will be sourced.

The current documentation should be sufficient. the package can be built using R CMD build (from command line).

The package then will be included as a dependency of caspr.

fdschneider commented 9 years ago

I just forked the repository and built a package from it: see here. But I still need to figure out how to call it from within caspr.

fdschneider commented 9 years ago

The input for the functions provided in the spatialwarnings package is a binary matrix. We needed a wrapper that transfers the landscape object into a binary matrix and then applies the function spatialwarnings::spatial_ews().

By commit 5b168620 this is now realised in the S3 methods of function indicators() for individual landscape objects as well as for output of the ca(), but as far as I see this only works for square landscape objects! .

Note: I had to disable the automatic plotting of a visual report in spatialwarnings::spatial_ews().