Skip to content

Commit

Permalink
fix 'process_trace_back' for #14
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Jun 22, 2023
1 parent eb00894 commit 800366f
Show file tree
Hide file tree
Showing 3 changed files with 21 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.036
Version: 0.1.1.037
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
22 changes: 19 additions & 3 deletions R/tracer-define.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,17 @@ process_back_trace <- function (trace_dat, fn_name) {
# or 'tryCatch' calls. Those will then be first on the call_env list in the
# final reduction to one row, below.
has_fn_name <- vapply (trace_dat$call, function (i) {
index <- seq_along (i)
p <- NULL
while (is.null (p) && length (index) > 0L) {
p <- tryCatch (
parse (text = i [index], encoding = "UTF-8"),
error = function (e) NULL
)
index <- index [-length (index)]
}
pd <- tryCatch (
utils::getParseData (parse (text = i)),
utils::getParseData (p),
error = function (e) NULL
)
if (is.null (pd)) {
Expand All @@ -202,8 +211,14 @@ process_back_trace <- function (trace_dat, fn_name) {
fns <- pd$text [index]
return (any (fns == fn_name))
}, logical (1L))
parent_level <- sort (unique (trace_dat$parent [which (has_fn_name)]))
trace_dat <- trace_dat [which (trace_dat$parent %in% parent_level), ]

# These 2 lines are needed to catch expect_error in geodist_vec, but then
# they miss all 'tryCatch' calls:
# parent_level <- sort (unique (trace_dat$parent [which (has_fn_name)]))
# trace_dat <- trace_dat [which (trace_dat$parent %in% parent_level), ]

trace_dat <- trace_dat [which (has_fn_name), ]

if (nrow (trace_dat) == 0L) {
return (call_envs)
}
Expand All @@ -229,6 +244,7 @@ process_back_trace <- function (trace_dat, fn_name) {
call_envs$namespace [index] <- trace_dat$scope [index]
}
call_envs <- call_envs [which (call_envs$namespace != "typetracer"), ]
call_envs <- call_envs [which (!grepl ("typetracer", call_envs$file)), ]
if (nrow (call_envs) > 0L) {
# assume first branch of trace_back is desired env
call_envs <- call_envs [1, ]
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.036",
"version": "0.1.1.037",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 800366f

Please sign in to comment.