Skip to content

Comments

Fixing tuning.r to work with single-raster models#1

Open
darcyj wants to merge 1 commit intocran:masterfrom
darcyj:patch-1
Open

Fixing tuning.r to work with single-raster models#1
darcyj wants to merge 1 commit intocran:masterfrom
darcyj:patch-1

Conversation

@darcyj
Copy link

@darcyj darcyj commented May 24, 2018

Before this change, ENMevaluate does NOT work when forming a model using a single raster layer.

NOTE: this is NOT the same issue that arises when a single raster layer is used instead of a raster stack with only one layer in it. That's a different problem. The bug I'm fixing here occurs when env (the input to tuning() ) is a raster stack containing one raster.

Instead, there's some data.frame subsetting that happens within the tune() function that assumes a 2-dimensional data.frame. Usually that's fine, until you only have one raster layer and therefore the data.frame objects "train.val", "test.val" and "bg.val" each have a single column. When they are subset using [some_logical, ], R( in its infinite wisdom) returns a vector, NOT a data.frame. This is solved by adding "drop=FALSE", which I've done here.

Before this change, ENMevaluate does NOT work when forming a model using a single raster layer. 

NOTE: this is NOT the same issue that arises when a single raster layer is used instead of a raster stack with only one layer in it. That's a different problem. The bug I'm fixing here occurs when env (the input to tuning() ) is a raster stack containing one raster. 

Instead, there's some data.frame subsetting that happens within the tune() function that assumes a 2-dimensional data.frame. Usually that's fine, until you only have one raster layer and therefore the data.frame objects "train.val", "test.val" and "bg.val" each have a single column. When they are subset using [some_logical, ], R( in its infinite wisdom) returns a vector, NOT a data.frame. This is solved by adding "drop=FALSE", which I've done here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant