Skip to content

Newbie trying to understand $ so I can understand acf function in stats

2 messages · Dick Knox, Peter Ehlers

#
I am trying to understand the function acf
stats:::acf shows me the function

I am having trouble understanding the usage "$acf" in the following

   acf <- array(.C(R_acf, as.double(x), as.integer(sampleT),
         as.integer(nser), as.integer(lag.max), as.integer(type ==
             "correlation"), acf = double((lag.max + 1L) * nser *
             nser), NAOK = TRUE)$acf, c(lag.max + 1L, nser, nser))

I interpret it as ... we are forming an array of dimensionality 3, and 
the contents of the array come from invoking a C program R_acf while the 
values of the 3 dimensions are lag.max + 1L, nser, and nser.

simplified acf<-array(.C(args)$acf, c(some dimensions))

Adding some spaces and line feeds to make it easier to read
    acf <- array
(
   .C(
     R_acf,
     as.double(x),
     as.integer(sampleT),
     as.integer(nser),
     as.integer(lag.max),
     as.integer(type == "correlation"),
     acf = double((lag.max + 1L) * nser * nser),
     NAOK = TRUE
     )$acf,

   c(lag.max + 1L, nser, nser)
)

R Language Definition section 3.4 "Indexing" explains that $ is used in 
indexing.
But
The light is not coming on when I try to apply that knowledge to 
understanding what is happening here.

Can anyone suggest a path out of the darkness?

Also, when I search my system for a file named R_acf, I dont find one.
I assume that this is because R_acf got task built into an executable 
and my distribution has the executable? I got R from "yum install R" on 
fedora linux. To see the source I apparently need to download a full 
compilable distribution of R.

Dick
#
On 2010-12-08 09:16, Dick Knox wrote:
[...snip...]
Here's a flashlight:
The .C() call returns a list of 6 objects, one of which is a vector
named 'acf'. That one is extracted by the '.C()$acf' construct and
is then used in creating the array.
You can download the sources from CRAN: get R-patched.tar.gz. If you
frequently want to look at source code, it's probably a good idea to
have that file locally. It will include comments that are stripped
out of the compiled version.

Or you can access the sources online (and hence most up-to-date) at:

  https://svn.r-project.org/R/trunk/src/

where you will find acf in

  https://svn.r-project.org/R/trunk/src/library/stats/src/filter.c

(and no, it's not called R_acf there; the 'R_' gets added in
compilation).

Uwe Ligges has written an article in R News (October 2006) on
accessing sources.


Peter Ehlers