wpeterman / ResistanceGA

Optimize resistance surfaces using Genetic Algorithms
37 stars 15 forks source link

CS.prep function #1

Closed jeffreyhanson closed 10 years ago

jeffreyhanson commented 10 years ago

Hi,

This looks amazing! Thank you!

I was trying out this package and running through the code in the vignette, and got to here:

CS.inputs <- CS.prep(n.POPS=length(sample.locales), response=CS.response, CS_Point.File=paste0(write.dir,"samples.txt"), CS.program=CS.program)

and hit this error:

Error in if (TEST.response == FALSE) { : argument is of length zero

I think the problem in line 2153:

The code is currently this:

if(!is.null(response)) {TEST.response <- (is.vector(response) | ncol(response)==1)

but if the response is a vector then this returns a logical(0),

I think you want this (two pipes):

if(!is.null(response)) {TEST.response <- (is.vector(response) || ncol(response)==1)

so that a vector input will return TRUE.

I'm still learning how to use github so apologies if I'm doing it wrong :)

wpeterman commented 10 years ago

Hi paleo13--

Thanks for checking out ResistanceGA and for notifying me of this issue. I've updated the code to use double pipes.

Best--Bill

__Bill Peterman_ Postdoctoral Research Associate Illinois Natural History Survey Prairie Research Institute University of Illinois 1816 S. Oak Street Champaign, Illinois 61820 Office: 217.244.8191 Web Page http://petermanresearch.weebly.com/

On Sun, Sep 21, 2014 at 7:29 AM, paleo13 notifications@github.com wrote:

Hi,

This looks amazing! Thank you!

I was trying out this package and running through the code in the vignette, and got to here:

CS.inputs <- CS.prep(n.POPS=length(sample.locales), response=CS.response, CS_Point.File=paste0(write.dir,"samples.txt"), CS.program=CS.program)

and hit this error:

Error in if (TEST.response == FALSE) { : argument is of length zero

I think the problem in line 2153:

The code is currently this:

if(!is.null(response)) {TEST.response <- (is.vector(response) | ncol(response)==1)

but if the response is a vector then this returns a logical(0),

I think you want this (two pipes):

if(!is.null(response)) {TEST.response <- (is.vector(response) || ncol(response)==1)

so that a vector input will return TRUE.

I'm still learning how to use github so apologies if I'm doing it wrong :)

— Reply to this email directly or view it on GitHub https://github.com/wpeterman/ResistanceGA/issues/1.

jeffreyhanson commented 10 years ago

Hi,

Just noticed a potential bug in Combine_Surfaces in ResistanceGA_Functions.R

Lines 168-174 are this:

  } else if (equation==8) {
    r[[i]] <- Inv.Ricker(rast,parm)
    EQ <- "Inverse Ricker"  

  } else if (equation==8) {
    r[[i]] <- Ricker(rast,parm)
    EQ <- "Ricker"

I suspect line 172 should be:

  } else if (equation==9) {
jeffreyhanson commented 10 years ago

Ah wait, not this

} else if (equation==9) {

but maybe this?

} else if (equation==4) {

Otherwise if equation==4 it just gets sucked up in the else at the end of the if-else chain,

wpeterman commented 10 years ago

Thank you again, paleo13. This error had escaped me during the previous update of the code. I've made the fix in v2.0-11

__Bill Peterman_ Postdoctoral Research Associate Illinois Natural History Survey Prairie Research Institute University of Illinois 1816 S. Oak Street Champaign, Illinois 61820 Office: 217.244.8191 Web Page http://petermanresearch.weebly.com/

On Tue, Sep 30, 2014 at 1:10 AM, paleo13 notifications@github.com wrote:

Ah wait, not this

} else if (equation==9) {

but maybe this?

} else if (equation==4) {

Otherwise if equation==4 it just gets sucked up in the else at the end of the if-else chain,

— Reply to this email directly or view it on GitHub https://github.com/wpeterman/ResistanceGA/issues/1#issuecomment-57271156 .

jeffreyhanson commented 10 years ago

sorry I just realised I forgot to close this, thanks for patching the code :)