A chunk hook is a function that is triggered by a chunk option when the value of this chunk option is not NULL. Chunk hooks provide a way for you to execute additional tasks beyond running the code in a chunk. For example, you may want to post-process plots (e.g., Section 13.1 and Section 13.2), or record the time taken by a code chunk (Section 13.3). Such tasks may not be essential to the computing or analysis in the report, but they can be useful for other purposes (e.g., enhance plots or help you identify the most time-consuming chunks).
You can use chunk hooks purely for their side-effects (e.g., only printing out certain information to the console), or for their returned values, which will be written to the output document if the value is a character value.