From 800366f13a059d62c23b1327a8616e1f817f1c4f Mon Sep 17 00:00:00 2001 From: mpadge Date: Thu, 22 Jun 2023 16:46:28 +0200 Subject: [PATCH] fix 'process_trace_back' for #14 --- DESCRIPTION | 2 +- R/tracer-define.R | 22 +++++++++++++++++++--- codemeta.json | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1f83aad..5a6201e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")), diff --git a/R/tracer-define.R b/R/tracer-define.R index 8acc777..a0bd367 100644 --- a/R/tracer-define.R +++ b/R/tracer-define.R @@ -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)) { @@ -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) } @@ -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, ] diff --git a/codemeta.json b/codemeta.json index b444ac2..12e4f88 100644 --- a/codemeta.json +++ b/codemeta.json @@ -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",