Skip to content

Commit

Permalink
fix call_env tracing to close #14
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Jun 22, 2023
1 parent ef84c48 commit eb00894
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: typetracer
Title: Trace Function Parameter Types
Version: 0.1.1.035
Version: 0.1.1.036
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
11 changes: 8 additions & 3 deletions R/tracer-define.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ typetracer_header <- function () {
utils::getFromNamespace ("process_back_trace", "typetracer")
# Initial trace has to be called in this environment:
trace_dat <- rlang::trace_back (bottom = fn_env)

# Uncomment this for debugging, and add "trace_dat" to "trace_objs" at start
# of "load_traces" fn:
# typetracer_env$data$trace_dat <- trace_dat

typetracer_env$data$call_envs <-
typetracer_env$process_back_trace (trace_dat, typetracer_env$fn_name)

Expand Down Expand Up @@ -185,8 +190,7 @@ process_back_trace <- function (trace_dat, fn_name) {
# includes any embedded environments of those, such as testthat expectations
# or 'tryCatch' calls. Those will then be first on the call_env list in the
# final reduction to one row, below.
tt <- as.data.frame (trace_dat)
has_fn_name <- vapply (tt$call, function (i) {
has_fn_name <- vapply (trace_dat$call, function (i) {
pd <- tryCatch (
utils::getParseData (parse (text = i)),
error = function (e) NULL
Expand All @@ -198,7 +202,8 @@ process_back_trace <- function (trace_dat, fn_name) {
fns <- pd$text [index]
return (any (fns == fn_name))
}, logical (1L))
trace_dat <- trace_dat [which (has_fn_name), ]
parent_level <- sort (unique (trace_dat$parent [which (has_fn_name)]))
trace_dat <- trace_dat [which (trace_dat$parent %in% parent_level), ]
if (nrow (trace_dat) == 0L) {
return (call_envs)
}
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"codeRepository": "https://github.com/mpadge/typetracer",
"issueTracker": "https://github.com/mpadge/typetracer/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.1.1.035",
"version": "0.1.1.036",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit eb00894

Please sign in to comment.