How is the order of execution of code chunks in a Literate Programming tool like noweb or Rmarkdown determined?

258 Views Asked by At

I am reading this and it says :

Because of the way notangle extracts and assembles its input, the program can be presented and explained in the best order for human understanding. notangle will make sure that the program chunks are in the right order for the compiler or interpreter.

My query is : How does the noweb compiler determine the order of code chunks ?

This says that :

An R Markdown document will have often have many code chunks. They are evaluated in order, in a single R session, and the state of the various variables in one code chunk are preserved in future chunks.

Is'nt Rmarkdown based on noweb ? Should it not automatically determine code chunk order like noweb ?

1

There are 1 best solutions below

0
On

Noweb chunks may be used as macros in other chunks so the order just boils down to what order notangle finds them in. For example if I tangled main.txt from this, the resulting text would be the letters A to E in alphabetical order.

<<main.txt>>=
<<A>>
<<D>>
<<D>>=
D
<<E>>
@
A text chunk that won't be in main.txt.
<<F>>=
Since this chunk is not referred to in any other chunk it will not appear in main.txt.
<<A>>=
A
<<B>>
<<C>>
<<E>>=
E
<<C>>=
C
<<B>>=
B