On Thu, Dec 19, 2013 at 4:23 AM, Roger Bivand <Roger.Bivand@nhh.no> wrote:

> On Wed, 18 Dec 2013, Josh O'Brien wrote:
>

<...snip...>

By the way, always avoid accessing S4 objects directly using @, do use
> slot(obj, "slotname") - the sapply should read:
>
> area = sapply(slot(SPclus, "polygons"), slot, "area")
>
> for the SO version with possibly incorrect areas, and
>
> area = gArea(SPclus, byid=TRUE)
>
> for correct ones.


Would you mind explaining why the functional form, slot(obj, "slotname"),
should always be used instead of obj@slotname ? I've seen this admonition
repeatedly -- I think just from you -- and don't know whether it's a purely
stylistic preference on your part, or whether there  is some other
rationale for preferring that form.

FWIW, the ?slot help page doesn't include any such direction, only noting
in its documentation of the name argument that:

          In the case of the ‘slot’ function, ‘name’ can be any
          expression that evaluates to a valid slot in the class
          definition.  Generally, the only reason to use the functional
          form rather than the simpler operator is _because_ the slot
          name has to be computed.

Is there some other reason to prefer the functional form?

Josh


> Finally, never use T/F for TRUE and FALSE, try:
>
> T <- FALSE
>
> and TRUE <- FALSE
>
> and see the difference.
>
> Terminally uninterested in winning points on SO,
>
> Roger
>
>
>>
>> --
>> View this message in context: http://r-sig-geo.2731867.n2.
>> nabble.com/Combining-polygons-and-calculating-their-area-i-
>> e-number-of-cells-tp7585395p7585401.html
>> Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand@nhh.no
>
>

	[[alternative HTML version deleted]]

