tests/testthat/test-call_chunk_utils.R

# get_pkg_name ----
test_that("Able to extract package name from pkg::fn call", {
  expect_identical(get_pkg_name(str2lang("rlang::sym('foo')")), "rlang")
})

test_that("Able to extract package name from unnamespaced function call", {
  expect_identical(get_pkg_name(str2lang("repro_chunk('foo')")), "shinyreprex")
})

test_that("When extract package from function call, base R packages are ignored", {
  expect_null(get_pkg_name(str2lang("nzchar('foo')")))
})

Try the shinyreprex package in your browser

Any scripts or data that you put into this service are public.

shinyreprex documentation built on April 27, 2026, 9:10 a.m.