Skip to content

Shows the relationship between calls on the stack. This function combines the results of sys.calls() and sys.parents() yielding a display that shows how frames on the call stack are related.

Usage

cst()

Examples

# If all evaluation is eager, you get a single tree
f <- function() g()
g <- function() h()
h <- function() cst()
f()
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5.         └─purrr::map(...)
#>   6.           └─pkgdown .f(.x[[i]], ...)
#>   7.             ├─base::withCallingHandlers(...)
#>   8.             └─pkgdown:::data_reference_topic(...)
#>   9.               └─pkgdown:::run_examples(...)
#>  10.                 └─pkgdown:::highlight_examples(code, topic, env = env)
#>  11.                   └─downlit::evaluate_and_highlight(...)
#>  12.                     └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  13.                       └─evaluate:::evaluate_call(...)
#>  14.                         ├─evaluate timing_fn(...)
#>  15.                         ├─evaluate handle(...)
#>  16.                         │ └─base::try(f, silent = TRUE)
#>  17.                         │   └─base::tryCatch(...)
#>  18.                         │     └─base tryCatchList(expr, classes, parentenv, handlers)
#>  19.                         │       └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  20.                         │         └─base doTryCatch(return(expr), name, parentenv, handler)
#>  21.                         ├─base::withCallingHandlers(...)
#>  22.                         ├─base::withVisible(...)
#>  23.                         └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  24.                           └─base::eval(expr, envir, enclos)
#>  25.                             └─base::eval(expr, envir, enclos)
#>  26.                               └─f()
#>  27.                                 └─g()
#>  28.                                   └─h()
#>  29.                                     └─lobstr::cst()

# You get multiple trees with delayed evaluation
try(f())
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5.         └─purrr::map(...)
#>   6.           └─pkgdown .f(.x[[i]], ...)
#>   7.             ├─base::withCallingHandlers(...)
#>   8.             └─pkgdown:::data_reference_topic(...)
#>   9.               └─pkgdown:::run_examples(...)
#>  10.                 └─pkgdown:::highlight_examples(code, topic, env = env)
#>  11.                   └─downlit::evaluate_and_highlight(...)
#>  12.                     └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  13.                       └─evaluate:::evaluate_call(...)
#>  14.                         ├─evaluate timing_fn(...)
#>  15.                         ├─evaluate handle(...)
#>  16.                         │ └─base::try(f, silent = TRUE)
#>  17.                         │   └─base::tryCatch(...)
#>  18.                         │     └─base tryCatchList(expr, classes, parentenv, handlers)
#>  19.                         │       └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  20.                         │         └─base doTryCatch(return(expr), name, parentenv, handler)
#>  21.                         ├─base::withCallingHandlers(...)
#>  22.                         ├─base::withVisible(...)
#>  23.                         └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  24.                           └─base::eval(expr, envir, enclos)
#>  25.                             └─base::eval(expr, envir, enclos)
#>  26.                               ├─base::try(f())
#>  27.                               │ └─base::tryCatch(...)
#>  28.                               │   └─base tryCatchList(expr, classes, parentenv, handlers)
#>  29.                               │     └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  30.                               │       └─base doTryCatch(return(expr), name, parentenv, handler)
#>  31.                               └─f()
#>  32.                                 └─g()
#>  33.                                   └─h()
#>  34.                                     └─lobstr::cst()

# Pay attention to the first element of each subtree: each
# evaluates the outermost call
f <- function(x) g(x)
g <- function(x) h(x)
h <- function(x) x
try(f(cst()))
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5.         └─purrr::map(...)
#>   6.           └─pkgdown .f(.x[[i]], ...)
#>   7.             ├─base::withCallingHandlers(...)
#>   8.             └─pkgdown:::data_reference_topic(...)
#>   9.               └─pkgdown:::run_examples(...)
#>  10.                 └─pkgdown:::highlight_examples(code, topic, env = env)
#>  11.                   └─downlit::evaluate_and_highlight(...)
#>  12.                     └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  13.                       └─evaluate:::evaluate_call(...)
#>  14.                         ├─evaluate timing_fn(...)
#>  15.                         ├─evaluate handle(...)
#>  16.                         │ └─base::try(f, silent = TRUE)
#>  17.                         │   └─base::tryCatch(...)
#>  18.                         │     └─base tryCatchList(expr, classes, parentenv, handlers)
#>  19.                         │       └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  20.                         │         └─base doTryCatch(return(expr), name, parentenv, handler)
#>  21.                         ├─base::withCallingHandlers(...)
#>  22.                         ├─base::withVisible(...)
#>  23.                         └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  24.                           └─base::eval(expr, envir, enclos)
#>  25.                             └─base::eval(expr, envir, enclos)
#>  26.                               ├─base::try(f(cst()))
#>  27.                               │ └─base::tryCatch(...)
#>  28.                               │   └─base tryCatchList(expr, classes, parentenv, handlers)
#>  29.                               │     └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  30.                               │       └─base doTryCatch(return(expr), name, parentenv, handler)
#>  31.                               ├─f(cst())
#>  32.                               │ └─g(x)
#>  33.                               │   └─h(x)
#>  34.                               └─lobstr::cst()

# With a little ingenuity you can use it to see how NSE
# functions work in base R
with(mtcars, {cst(); invisible()})
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5.         └─purrr::map(...)
#>   6.           └─pkgdown .f(.x[[i]], ...)
#>   7.             ├─base::withCallingHandlers(...)
#>   8.             └─pkgdown:::data_reference_topic(...)
#>   9.               └─pkgdown:::run_examples(...)
#>  10.                 └─pkgdown:::highlight_examples(code, topic, env = env)
#>  11.                   └─downlit::evaluate_and_highlight(...)
#>  12.                     └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  13.                       └─evaluate:::evaluate_call(...)
#>  14.                         ├─evaluate timing_fn(...)
#>  15.                         ├─evaluate handle(...)
#>  16.                         │ └─base::try(f, silent = TRUE)
#>  17.                         │   └─base::tryCatch(...)
#>  18.                         │     └─base tryCatchList(expr, classes, parentenv, handlers)
#>  19.                         │       └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  20.                         │         └─base doTryCatch(return(expr), name, parentenv, handler)
#>  21.                         ├─base::withCallingHandlers(...)
#>  22.                         ├─base::withVisible(...)
#>  23.                         └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  24.                           └─base::eval(expr, envir, enclos)
#>  25.                             └─base::eval(expr, envir, enclos)
#>  26.                               ├─base::with(...)
#>  27.                               └─base::with.default(...)
#>  28.                                 └─base::eval(substitute(expr), data, enclos = parent.frame())
#>  29.                                   └─base::eval(substitute(expr), data, enclos = parent.frame())
#>  30.                                     └─lobstr::cst()
invisible(subset(mtcars, {cst(); cyl == 0}))
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5.         └─purrr::map(...)
#>   6.           └─pkgdown .f(.x[[i]], ...)
#>   7.             ├─base::withCallingHandlers(...)
#>   8.             └─pkgdown:::data_reference_topic(...)
#>   9.               └─pkgdown:::run_examples(...)
#>  10.                 └─pkgdown:::highlight_examples(code, topic, env = env)
#>  11.                   └─downlit::evaluate_and_highlight(...)
#>  12.                     └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  13.                       └─evaluate:::evaluate_call(...)
#>  14.                         ├─evaluate timing_fn(...)
#>  15.                         ├─evaluate handle(...)
#>  16.                         │ └─base::try(f, silent = TRUE)
#>  17.                         │   └─base::tryCatch(...)
#>  18.                         │     └─base tryCatchList(expr, classes, parentenv, handlers)
#>  19.                         │       └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  20.                         │         └─base doTryCatch(return(expr), name, parentenv, handler)
#>  21.                         ├─base::withCallingHandlers(...)
#>  22.                         ├─base::withVisible(...)
#>  23.                         └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  24.                           └─base::eval(expr, envir, enclos)
#>  25.                             └─base::eval(expr, envir, enclos)
#>  26.                               ├─base::subset(...)
#>  27.                               └─base::subset.data.frame(...)
#>  28.                                 └─base::eval(e, x, parent.frame())
#>  29.                                   └─base::eval(e, x, parent.frame())
#>  30.                                     └─lobstr::cst()

# You can also get unusual trees by evaluating in frames
# higher up the call stack
f <- function() g()
g <- function() h()
h <- function() eval(quote(cst()), parent.frame(2))
f()
#>      
#>   1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#>   2.   └─pkgdown::build_site(...)
#>   3.     └─pkgdown:::build_site_local(...)
#>   4.       └─pkgdown::build_reference(...)
#>   5.         └─purrr::map(...)
#>   6.           └─pkgdown .f(.x[[i]], ...)
#>   7.             ├─base::withCallingHandlers(...)
#>   8.             └─pkgdown:::data_reference_topic(...)
#>   9.               └─pkgdown:::run_examples(...)
#>  10.                 └─pkgdown:::highlight_examples(code, topic, env = env)
#>  11.                   └─downlit::evaluate_and_highlight(...)
#>  12.                     └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  13.                       └─evaluate:::evaluate_call(...)
#>  14.                         ├─evaluate timing_fn(...)
#>  15.                         ├─evaluate handle(...)
#>  16.                         │ └─base::try(f, silent = TRUE)
#>  17.                         │   └─base::tryCatch(...)
#>  18.                         │     └─base tryCatchList(expr, classes, parentenv, handlers)
#>  19.                         │       └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  20.                         │         └─base doTryCatch(return(expr), name, parentenv, handler)
#>  21.                         ├─base::withCallingHandlers(...)
#>  22.                         ├─base::withVisible(...)
#>  23.                         └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#>  24.                           └─base::eval(expr, envir, enclos)
#>  25.                             └─base::eval(expr, envir, enclos)
#>  26.                               └─f()
#>  27.                                 ├─g()
#>  28.                                 │ └─h()
#>  29.                                 │   └─base::eval(quote(cst()), parent.frame(2))
#>  30.                                 │     └─base::eval(quote(cst()), parent.frame(2))
#>  31.                                 └─lobstr::cst()