diff --git a/DESCRIPTION b/DESCRIPTION index 86433cf..9eed103 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: logrx Title: A Logging Utility Focus on Clinical Trial Programming Workflows -Version: 0.2.0 +Version: 0.2.1 Authors@R: c( person(given = "Nathan", diff --git a/NAMESPACE b/NAMESPACE index d926235..bc32ecc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ importFrom(tidyr,complete) importFrom(tidyr,pivot_wider) importFrom(utils,capture.output) importFrom(utils,getParseData) +importFrom(utils,lsf.str) importFrom(waiter,spin_solar) importFrom(waiter,useWaiter) importFrom(waiter,waiter_hide) diff --git a/NEWS.md b/NEWS.md index bc35a53..46a8d26 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# logrx 0.2.1 + + - non-function objects are no longer returned as functions by `get_used_functions` (#154) + # logrx 0.2.0 - Major update release for logrx diff --git a/R/get.R b/R/get.R index 8dcbe72..9870557 100644 --- a/R/get.R +++ b/R/get.R @@ -211,14 +211,28 @@ get_used_functions <- function(file){ #' @importFrom dplyr mutate #' @importFrom rlang .data #' @importFrom purrr map +#' @importFrom utils lsf.str #' #' @return tibble that includes `library` #' #' @noRd #' get_library <- function(df){ - search_lookup <- map(search(), objects) - names(search_lookup) <- search() + + functions_only <- function(.x){ + intersect(ls(.x), lsf.str(.x)) + } + + # do not search CheckExEnv, this is created while examples are executed + # during build + # T and F are given a delayedAssign within the CheckExEnv environment, + # and when we check this environments objects, the promise for T and F + # are evaluated, and return: + # stop("T used instead of TRUE"), stop("F used instead of FALSE") + search_environ <- search()[search() != "CheckExEnv"] + + search_lookup <- map(search_environ, functions_only) + names(search_lookup) <- search_environ df$library <- unlist(map(df$function_name, ~get_first(., search_lookup))) df %>% diff --git a/tests/testthat/test-get.R b/tests/testthat/test-get.R index 8ad7a40..b477174 100644 --- a/tests/testthat/test-get.R +++ b/tests/testthat/test-get.R @@ -111,6 +111,26 @@ test_that("used functions returned correctly when file doesn't contain all token expect_identical(get_used_functions(filename), expected) }) +test_that("get_library returns correct function when a non-function + object of same name is available", { + + writeLines('search <- "dummy object"', "dummy.R") + + sys.source("dummy.R", envir = attach(NULL, name = "dummy")) + + actual <- get_library(tibble(function_name = "search", SYMBOL_PACKAGE = NA)) + + unlink("dummy.R") + detach("dummy") + + expected <- tibble::tribble( + ~function_name, ~ SYMBOL_PACKAGE, ~library, + "search", NA, "package:base" + ) + + expect_identical(actual, expected) +}) + test_that("parse does not fatal error when syntax issue occurs", { filename <- test_path("ref", "ex4.R")