[Rd] Error possibly related with environments/namespace

Roger Bivand Roger.Bivand at nhh.no
Wed Sep 30 12:55:34 CEST 2015


Frederico Mestre <mestre.frederico <at> gmail.com> writes:

> 
> Hello all,
> 
> I've got a problem with a function in a R package I've developed
> (MetaLandSim).
> 

The function with the problem is a GRASS script embedded in a portmanteau
function (doing too much at once). This list is not appropriate, and
http://lists.osgeo.org/mailman/listinfo/grass-stats would be much more
appropriate, as this has nothing to do with the development of R internals.

The function should return an S3 object (list of objects) with plot and
summary methods. Then you can see where problems are happening.

> 
> However if I load the exact same function in R it runs perfectly well.
> 
> This has something to do with environments, but I can't understand whats
> wrong. It is also related with the plotting, since if I set the argument
> plot.directions to FALSE I get no error.
> 
> Here's the code:
> 
> #Loading packages
> library(MetaLandSim)
> library(rgrass7)
> 
> #Loading required data
> data(rg_exp)
> 
> #Loading required maps
> presences <- system.file("examples/presences.asc", package="MetaLandSim")
> mask <- system.file("examples/landmask.asc", package="MetaLandSim")
> 
> #Start  GRASS using rgrass7
> initGRASS("C:/Program Files (x86)/GRASS GIS 7.0.0", home=tempdir())
> 
> #Running function
> range.map <- range_raster(presences.map=presences, re.out=rg_exp,
> mask.map=mask,plot.directions=TRUE)

The example fails because you expect a mask to be set, and remove it - if it
isn't there, the GRASS script fails. Adding:

execGRASS("r.mask", raster="map.mask") gets me further, but isn't the
problem, which is (in this case):

Browse[2]> 
debug: image(raster(readRAST("Nprobability")), main = "Northern probability")
Browse[2]> 
Creating BIL support files...
Exporting raster as floating values (bytes=8)
 100%
Error in image.default(raster(readRAST("Nprobability")), main = "Northern
probability") : 
  'z' must be a matrix

so there is an issue here, which might be addressed by raster::raster
(untried). Main take-home point - write simple functions and leave plota and
summaries to methods used on the output objects - anything else is hard to
debug and maintain.

Hope this clarifies,

Roger


> 
> Cheers,
> Frederico Mestre
>> 


More information about the R-devel mailing list