[R-sig-Geo] Error in writeRaster for signature RasterPCA

Vijay Ramesh rameshv at caryinstitute.org
Tue Mar 7 19:06:37 CET 2017


I am currently trying to obtain two rasters that are the Principal
component axes 1 and 2 for a list of bioclimatic variables that I am using.
I am using the rasterPCA() function that exists in the RStoolbox in R, but
I am unable to write it to a raster. Below is the code and the error that I
am getting:

library(raster)
library(RStoolbox)
##Loading the variables and then creating a raster stack, followed by a PCA
bio3 <- raster("C:\\Users\\rameshv\\bio3")
bio4 <- raster("C:\\Users\\rameshv\\bio4")
bio5 <- raster("C:\\Users\\rameshv\\bio5")
bio6 <- raster("C:\\Users\\rameshv\\bio6")
bio14 <- raster("C:\\Users\\rameshv\\bio_14")

pres_stack <- stack(bio3, bio4,bio5,bio6,bio14)

pre_pca <-  rasterPCA(pres_stack, nComp = 2)

writeRaster(pre_pca, "C:\\Users\\rameshv\\PC.tif")

Error in (function (classes, fdef, mtable) : unable to find an inherited
method for function ‘writeRaster’ for signature ‘"rasterPCA", "character"’

I even tried a modification of the above code

writeRaster(pre_pca,"C:\\Users\\rameshv\\4_PCAforR\\PC.asc",
format="ascii", bylayer=T)

Getting the same error as above: Error in (function (classes, fdef, mtable)
: unable to find an inherited method for function ‘writeRaster’ for
signature ‘"rasterPCA", "character"’

Any suggestions?
Vijay
-- 
Data Manager,
Barbara Han Lab,
Cary Institute of Ecosystem Studies,
2801 Sharon Turnpike, Millbrook, NY 12545
Lab Site : http://www.hanlab.science/
Personal Site : http://evolecol.weebly.com/
Phone : (845)-677-7600 Ext: 241

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list