0

I am trying to use the as.raster function of the raster package, but there is already a function with the same name in the grDevices package. So, I use the :: operator to differentiate between the two, but it doesn't appear to work. Can someone explain where I'm going wrong? Minimal working example below:

library("raster")
a <- matrix(1:15, ncol=3)
raster::as.raster(a)

Output:

Error in rgb(tx, tx, tx, maxColorValue = max) : 
color intensity 6, not in [0,1]

This error message is for the grDevices version of the function.

Dan
  • 11,370
  • 4
  • 43
  • 68
  • 1
    Did you carefully read the help page of `raster::as.raster`? It is doing exactly what it is supposed to do. You are confusing `raster` and `Raster` objects. –  Feb 11 '15 at 01:15

1 Answers1

3

You seem to be trying to convert a variable of class matrix into a variable of class RasterLayer. The command as.raster when it receives a matrix, assumes you are using the grDevices-package version, since the raster-package version is designed to accept a RasterLayer object.

In your example, simply use raster(a).

J. Win.
  • 6,662
  • 7
  • 34
  • 52