Skip to content
Discussion options

You must be logged in to vote

Here is the example in Quarto from the Cookbook

---
format: html
---

```{r}
knitr::knit_hooks$set(time_it = local({
  now <- NULL
  function(before, options) {
    if (before) {
      # record the current time before each chunk
      now <<- Sys.time()
    } else {
      # calculate the time difference after a chunk
      res <- difftime(Sys.time(), now, units = "secs")
      # return a character string to show the time
      paste("Time for this code chunk to run:", round(res,
        2), "seconds")
    }
  }
}))
```

```{r}
#| time_it: true
Sys.sleep(2)
```

So it is working, and I think it is working for you too

The code in my original post works, but only for the first chapter—it do…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@isaactpetersen
Comment options

@mcanouil
Comment options

mcanouil Jul 8, 2025
Collaborator

Comment options

You must be logged in to vote
1 reply
@isaactpetersen
Comment options

Answer selected by isaactpetersen
Comment options

You must be logged in to vote
2 replies
@cderv
Comment options

cderv Jul 8, 2025
Maintainer

@mcanouil
Comment options

mcanouil Jul 8, 2025
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants