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?