Skip to content

Commit

Permalink
separate 'get_param_str' fn from typetracer_header for #16
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Jun 22, 2023
1 parent fd14e91 commit 64522b3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 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.022
Version: 0.1.1.023
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265")),
Expand Down
39 changes: 22 additions & 17 deletions R/tracer-define.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,8 @@ typetracer_header <- function () {
)
}

# Return structure of parameters as character strings
# https://rpubs.com/maechler/R_language_objs
typetracer_env$get_str <- function (x, max.length = 1000L) { # nolint

r <- tryCatch (format (x), error = function (e) e)
r <- if (inherits (r, "error")) {
tryCatch (as.character (x), error = function (e) e)
} else {
paste (r, collapse = " ")
}
r <- if (inherits (r, "error")) {
tryCatch (utils::capture.output (x), error = function (e) e)
} else {
paste (r, collapse = " ")
}
substr (r, 1L, max.length)
}
# Bring in typetracer internal functions:
typetracer_env$get_str <- getFromNamespace ("get_param_str", "typetracer")

typetracer_env$data <- lapply (typetracer_env$par_names, function (p) {

Expand Down Expand Up @@ -157,3 +142,23 @@ typetracer_header <- function () {

rm (typetracer_env)
}

#' Return structure of parameters as character strings
#'
#' See https://rpubs.com/maechler/R_language_objs
#' @noRd
get_param_str <- function (x, max.length = 1000L) { # nolint

r <- tryCatch (format (x), error = function (e) e)
r <- if (inherits (r, "error")) {
tryCatch (as.character (x), error = function (e) e)
} else {
paste (r, collapse = " ")
}
r <- if (inherits (r, "error")) {
tryCatch (utils::capture.output (x), error = function (e) e)
} else {
paste (r, collapse = " ")
}
substr (r, 1L, max.length)
}
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.022",
"version": "0.1.1.023",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
18 changes: 2 additions & 16 deletions tests/testthat/_snaps/trace-fns.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,8 @@
typetracer_env$par_names <- c(typetracer_env$par_names,
typetracer_env$dot_names)
}
typetracer_env$get_str <- function(x, max.length = 1000L) {
r <- tryCatch(format(x), error = function(e) e)
r <- if (inherits(r, "error")) {
tryCatch(as.character(x), error = function(e) e)
}
else {
paste(r, collapse = " ")
}
r <- if (inherits(r, "error")) {
tryCatch(utils::capture.output(x), error = function(e) e)
}
else {
paste(r, collapse = " ")
}
substr(r, 1L, max.length)
}
typetracer_env$get_str <- getFromNamespace("get_param_str",
"typetracer")
typetracer_env$data <- lapply(typetracer_env$par_names, function(p) {
res <- NULL
if (p %in% ls(fn_env)) {
Expand Down

0 comments on commit 64522b3

Please sign in to comment.