Wednesday 15 August 2012

r - release code error but not in debug or on source -


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?

Version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin10.8.0 (64-bit) Location: [1] en_GB.UTF-8 / en_GB.UTF-8 / en_GB.UTF-8 / C /en_GB.UTF-8/en_GB.UTF-8 Attached Base Packages: [1] Statistics Graphics GDV Evil Dataset Methods Other Attached Packages Base: [1] raster_2.3-0 spidy .5-77 matrix_1.1-4 minis 4.1 gdata_2.13.3 rgdal_0.9-1 sp_1.0-15 Load through namespace (and not attached): [1] Boot_1.3-11 coda_0.16-1 deldir_0.1-5 grid_3.1.1 gtools_3.4.1 latissus 20-29 LearnBayes_2.15 MASS_7.3-33 nlme_3.1-118 parallel_3.1.1 splines_3.1.1 Tools Audio.1.1

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