falconepl
falconepl

Reputation: 398

Function grid.raster returns NULL in R

I've been trying to do some raster image manipulation in R language using grid package. The problem is that I cannot retrive a return value from grid.raster function. When I do:

result <- grid.raster(inputData)

instead of "a rastergrob grob" (as specified in a documentation) I receive a NULL object.

I've double checked it with an example from the documentation:

redGradient <- matrix(hcl(0, 80, seq(50, 80, 10)), nrow=4, ncol=5)
grid.newpage()
result <- grid.raster(redGradient)

Still result is just a NULL object. Is R doing some return value interception here? If so, how can I get it?

Upvotes: 1

Views: 1027

Answers (1)

Peyton
Peyton

Reputation: 7396

Use the rasterGrob function:

result <- rasterGrob(redGradient)

The two functions share a documentation page, but looking at the source, you can see that grid.raster creates the grob and then draws it, returning the value of grid.draw (NULL), whereas rasterGrob simply returns the grob.

Upvotes: 2

Related Questions