Now the interesting thing about all that we’ve done here is that nowhere is
the interesting code wrapped in either functions or loops: it’s not wrapped in
anything at all. There are loops, but they occurr after. Code such as

> y.a=analytic(y)

> phase=unwrap(Arg(y.a))

> f0.est=qr.solve(cbind(t,1),cbind(phase))[[1]]/(2*pi)

was written entirely without repetition in mind.

I have to admit that I did cheat a little bit. If you go back and look
at the code you’ll notice that each variable is assigned exactly once.
Hence the hiding of logic like

> analytic=function(u){

> n=length(u)

> m=n/2+1

> U=fft(u)/length(u)

> U[(m+1):n]=0

> fft(U,inv=T)

> }

into functions, because this is awkward to write without assigningU twice. Because in the main program each variable is only
assigned once, when a modification is made, it is trivial to decide which other
variables must be updated and how.