下面的代码块...
data(meuse.grid)
isS4(meuse.grid)
slotNames(meuse.grid)
#meuse.grid@names # this will fail
class(meuse.grid)
coordinates(meuse.grid) = ~x+y
isS4(meuse.grid)
slotNames(meuse.grid)
head(meuse.grid@data)
class(meuse.grid)
...产生以下输出:
library(sp)
data(meuse.grid)
isS4(meuse.grid)
#> [1] FALSE
slotNames(meuse.grid)
#> [1] ".Data" "names" "row.names" ".S3Class"
#meuse.grid@names # this will fail
class(meuse.grid)
#> [1] "data.frame"
coordinates(meuse.grid) = ~x+y
isS4(meuse.grid)
#> [1] TRUE
slotNames(meuse.grid)
#> [1] "data" "coords.nrs" "coords" "bbox" "proj4string"
head(meuse.grid@data)
#> part.a part.b dist soil ffreq
#> 1 1 0 0.0000000 1 1
#> 2 1 0 0.0000000 1 1
#> 3 1 0 0.0122243 1 1
#> 4 1 0 0.0434678 1 1
#> 5 1 0 0.0000000 1 1
#> 6 1 0 0.0122243 1 1
class(meuse.grid)
#> [1] "SpatialPointsDataFrame"
#> attr(,"package")
#> [1] "sp"
由reprex package(v0.2.1)于2018-11-24创建
因此看来slotNames
不能用来确定对象确实是否包含插槽,但是对此行为的解释是什么?