[R-sig-eco] error in layernames and RasterStack

Baldwin, Jim -FS jbaldwin at fs.fed.us
Fri Dec 7 16:20:41 CET 2012


That's because the function maxlike explicitly calls "layerNames(rasters)" in

     cd.names <- layerNames(rasters)

By typing 

   maxlike()

you can see the code and find the statement mentioned above.  The two fixes are (1) make your own version of maxlike with the "names" fix and/or write the developer of maxlike and let him or her know about this issue.

Jim

-----Original Message-----
From: Alok K. Bohara [mailto:bohara at unm.edu] 
Sent: Friday, December 07, 2012 7:03 AM
To: Baldwin, Jim -FS; r-sig-ecology at r-project.org
Subject: RE: error in layernames and RasterStack

Thanks Jim.  names(r) <--   command  worked...

I still get this error  although I  get the estimates and their standard errors...

> fm2 <- maxlike(~x1 + x2 + x3, r, xy)
Warning message:
In layerNames(rasters) :
  the layerNames function is obsolete. Use "names" instead

Coefficients:
               Est    SE      z  P(>|z|)
(Intercept) -0.817 0.221 -3.687 2.27e-04
x1           1.157 0.129  8.987 2.54e-19
x2           0.152 0.190  0.801 4.23e-01
x3          -0.102 0.109 -0.933 3.51e-01




Alok K. Bohara, Ph.D.
UNM


________________________________________
From: Baldwin, Jim -FS [jbaldwin at fs.fed.us]
Sent: Thursday, December 06, 2012 11:46 AM
To: Alok K. Bohara; r-sig-ecology at r-project.org
Subject: RE: error in layernames and RasterStack

I think you might want

      names(r) <-  c("x1", "x2", "x3")

rather than

      r at layernames <- c("x1", "x2", "x3")

Jim


-----Original Message-----
From: r-sig-ecology-bounces at r-project.org [mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of Alok K. Bohara
Sent: Thursday, December 06, 2012 10:26 AM
To: r-sig-ecology at r-project.org
Subject: [R-sig-eco] error in layernames and RasterStack

Hi:  I am trying to replicate  some commands in maxlike.


#***
library(raster)

set.seed(131)
x1 <- sort(rnorm(100))
x1 <- raster(outer(x1, x1), xmn=0, xmx=100, ymn=0, ymx=100)
x2 <- raster(matrix(runif(1e4), 100, 100), 0, 100, 0, 100)
x3 <- raster(matrix(c(0,1), 100, 100), 0, 100, 0, 100) r <- stack(x1, x2, x3) r at layernames <- c("x1", "x2", "x3")

#****

Error #1:  After the last line, I get an Error:

Error in checkSlotAssignment(object, name, value) :
  'layernames' is not a slot in class "RasterStack"
>



Error # 2:  Later, I also get an error:

In addition: Warning message:
> fm2 <- maxlike(~x1 + x2 + x3, r, xy)
Error in maxlike(~x1 + x2 + x3, r, xy) :
  at least 1 covariate in the formula is not in rasters.

In layerNames(rasters) :
  the layerNames function is obsolete. Use "names" instead



I am using  R 2.15.2.  I do not know if the error #2 is the result of the error #1.    Thanks.



Best,
Alok K. Bohara,
UNM

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology





This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.



More information about the R-sig-ecology mailing list