My code runs fine but package fails
I boiled it down
wtf & lt; -function (raster) stoppotonaut (class (r) == "rosterlear") return (as.matrix (r))}
When the source is done, So everything works fine when the function is part of a package, it fails. It runs well in debug mode, though, step by step.
library of mypackage - raster (ncol = 6, nrow = 6) r [] & lt; - runif (ncell R), 0,1) extent (r) & lt; - Error in matrix (C (0, 0, 6, 6), nrow = 2) wtf (r) # as.vector (data): # No method for coercing a vector # traceback # 5 as. Vector (data) ) # 4 array for this array (x, c (length (x), 1l), if (Is! N is.null (names (x)) list (name (x), # null) second tap) # 3 as.matrix.default (r) # 2 as.matrix (r) in the area. R # 7 # 1 wtf (s)
I 'I came to know about this That is why this happens and how to move the build is cured, the check is clear, so what is happening?
The problem is solved What will be the next question to ask and find out?
Traceback shows that. As used by default, instead of the raster type. I believe that if you add this name to your namespace file, then this problem is resolved:
Import (raster)
Or when you explicitly tell about the matrix you want:
wtf < - Function (r) {stopifnot (inherits (r, "rasterlayer")) raster :: as.matrix (r)}
Instead of manually testing for class membership, You can consider a more formal (S4) approach:
if iterative ("wtf") {setGeneric ("wtf", function (x, ...) standardGeneric ("Wtf")} setMethod ("wtf", sign (x = 'rasterlayer'), function (x, ...) {raster :: as.matrix X}})
< / Div>
No comments:
Post a Comment