This method for recipes::recipe() handles the case when x is an sf::sf
object, as commonly used in Species Distribution Model, and generates a
spatial_recipe.
Arguments
- x
An sf::sf data frame.
- ...
parameters to be passed to
recipes::recipe()
Value
An object of class spatial_recipe, which is a derived version of
recipes::recipe() , see the manpage for recipes::recipe() for details.
Details
recipes::recipe() are not natively compatible with sf::sf objects. The
problem is that the geometry column of sf::sf objects is a list, which is
incompatible with the translation of formulae in recipes::recipe(). This
method strips the geometry column from the data.frame and replaces it
with a simple X and Y columns before any further operations, thus
allowing the usual processing by recipes::recipe() to succeed (X and Y
are give the role of coords in a spatial recipe). When prepping and baking a
spatial_recipe, if a data.frame or tibble without coordinates is used as
training or new_data, dummy X and Y columns are generated and filled
with NAs. NOTE that order matters! You need to use the syntax
recipe(x=sf_obj, formula=class~.) for the method to successfully detect the
sf::sf object. Starting with formula will fail.
