From ce701b802629a5dd234f72a60a2a35721e18c57f Mon Sep 17 00:00:00 2001 From: mpadge Date: Wed, 21 Jun 2023 18:00:10 +0200 Subject: [PATCH] dump 'trace_file' and 'call_env' in to trace results for #14 --- DESCRIPTION | 2 +- R/load-and-clear-traces.R | 12 ++++++++++++ codemeta.json | 2 +- tests/testthat/test-trace-fns.R | 9 +++++---- tests/testthat/test-trace-package.R | 15 +++++++++------ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3d13032..b052e75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: typetracer Title: Trace Function Parameter Types -Version: 0.1.1.014 +Version: 0.1.1.015 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/load-and-clear-traces.R b/R/load-and-clear-traces.R index 2decf94..a9b0f21 100644 --- a/R/load-and-clear-traces.R +++ b/R/load-and-clear-traces.R @@ -50,10 +50,22 @@ load_traces <- function (files = FALSE, quiet = FALSE) { par_uneval <- I (lapply (tr_i, function (i) i$par_uneval)) par_eval <- I (lapply (tr_i, function (i) i$par_eval)) + call_envs <- do.call (rbind, lapply (tr_i, function (i) { + ci <- i$call_envs + if (nrow (ci) == 0L) { + ci <- ci [1, ] # auto-fills with NA + } + return (ci) + })) + call_envs$call_env <- paste0 (call_envs$namespace, "::", call_envs$name) + call_envs$call_env [which (is.na (call_envs$name))] <- NA_character_ + tibble::tibble ( trace_name = i, trace_number = num_traces, trace_source = trace_source, + trace_file = call_envs$file, + call_env = call_envs$call_env, fn_name = fn_name, fn_call_hash = fn_call_hash, par_name = par_name, diff --git a/codemeta.json b/codemeta.json index 25e5406..49c8d1a 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.014", + "version": "0.1.1.015", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-trace-fns.R b/tests/testthat/test-trace-fns.R index 9288d57..1427f67 100644 --- a/tests/testthat/test-trace-fns.R +++ b/tests/testthat/test-trace-fns.R @@ -57,13 +57,14 @@ test_that ("trace call", { expect_s3_class (x, "tbl_df") expect_equal (nrow (x), 2L) # x and y - expect_equal (ncol (x), 13L) + expect_equal (ncol (x), 15L) expect_identical ( names (x), c ( - "trace_name", "trace_number", "fn_name", - "fn_call_hash", "par_name", "class", - "typeof", "mode", "storage_mode", "length", + "trace_name", "trace_number", + "trace_file", "call_env", + "fn_name", "fn_call_hash", "par_name", + "class", "typeof", "mode", "storage_mode", "length", "formal", "uneval", "eval" ) ) diff --git a/tests/testthat/test-trace-package.R b/tests/testthat/test-trace-package.R index 133777d..70e6967 100644 --- a/tests/testthat/test-trace-package.R +++ b/tests/testthat/test-trace-package.R @@ -28,8 +28,9 @@ test_that ("trace installed package", { expect_identical ( names (x0), c ( - "trace_number", "trace_source", "fn_name", - "fn_call_hash", "par_name", "class", + "trace_number", "trace_source", + "trace_file", "call_env", + "fn_name", "fn_call_hash", "par_name", "class", "typeof", "mode", "storage_mode", "length", "formal", "uneval", "eval", "source" ) @@ -46,8 +47,9 @@ test_that ("trace installed package", { expect_identical ( names (x1), c ( - "trace_number", "trace_source", "fn_name", - "fn_call_hash", "par_name", "class", + "trace_number", "trace_source", + "trace_file", "call_env", + "fn_name", "fn_call_hash", "par_name", "class", "typeof", "mode", "storage_mode", "length", "formal", "uneval", "eval", "source" ) @@ -91,8 +93,9 @@ test_that ("trace source package", { expect_identical ( names (x0), c ( - "trace_number", "trace_source", "fn_name", - "fn_call_hash", "par_name", "class", + "trace_number", "trace_source", + "trace_file", "call_env", + "fn_name", "fn_call_hash", "par_name", "class", "typeof", "mode", "storage_mode", "length", "formal", "uneval", "eval", "source" )