Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsGOC: NAs introduced by coercion #14

Closed
achubaty opened this issue Oct 13, 2016 · 4 comments
Closed

gsGOC: NAs introduced by coercion #14

achubaty opened this issue Oct 13, 2016 · 4 comments

Comments

@achubaty
Copy link
Owner

The following reprex shows the problem:

patchy <- raster(system.file("extdata/patchy.asc", package = "grainscape2"))
patchyCost <- reclassify(patchy, rcl = cbind(c(1,2,3,4,5), c(1, 10, 8, 3, 6)))
patchyMPG <- gsMPG(patchyCost, patch = (patchyCost == 1))
patchyGOC <- gsGOC(patchyMPG, nThresh = 100)
@ecologics
Copy link
Collaborator

ecologics commented Oct 17, 2016

I think this is a real error. I tracked it to line 321 of the code (the GitHub version). This line throws the warning:

V(componentGraph)$totalPatchArea <- as.numeric(unlist(sapply(sourcePatchId, function(x)
          sum(patchAreaLookup[patchAreaLookup[, 1] %in% as.numeric(x), 2]))))

I am not sure, but I think it is because the patchAreaLookup table produced at line 317 contains three columns of identical values, This suggests that the attributes patchArea.value, patchEdgeArea.value and coreArea.value are not being passed correctly to the gsMPG object. It looks like these all contain patchId numbers rather than areas.

So at the very least patchAreaLookup is wrong, and this might be the key to figuring out why the warning is being thrown.

@ecologics
Copy link
Collaborator

I think I just resolved this. There were two problems. The patchAreaLookup was not using the .count value. The second was the one that was throwing the warning was the strsplit(x..) bit that appears for the other variables was somehow omitted.

It now runs without warnings.

I "committed" this change using the online editor in GitHub. Hope this okay. Can you confirm that I have fixed what was probably just a code conversion typo.

@achubaty
Copy link
Owner Author

That's great! i had encountered the .count / .value issue previously and clearly forgot to follow through with my updates in that function. Thanks for resolving.

@achubaty
Copy link
Owner Author

achubaty commented Oct 17, 2016

fixed in 0e0ef44 / dccae8d

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

No branches or pull requests

2 participants