From 11b6df257f8eaa76f2ac11d0bc2c7dfa51e3a897 Mon Sep 17 00:00:00 2001 From: nicholas-masel Date: Sat, 28 Jan 2023 14:49:58 -0500 Subject: [PATCH 1/6] Closes #154 --- R/get.R | 7 ++++++- tests/testthat/test-get.R | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/R/get.R b/R/get.R index 8dcbe72..8b4db92 100644 --- a/R/get.R +++ b/R/get.R @@ -217,7 +217,12 @@ get_used_functions <- function(file){ #' @noRd #' get_library <- function(df){ - search_lookup <- map(search(), objects) + + functions_only <- function(.x){ + intersect(ls(.x), lsf.str(.x)) + } + + search_lookup <- map(search(), functions_only) names(search_lookup) <- search() df$library <- unlist(map(df$function_name, ~get_first(., search_lookup))) diff --git a/tests/testthat/test-get.R b/tests/testthat/test-get.R index 8ad7a40..0b92fbe 100644 --- a/tests/testthat/test-get.R +++ b/tests/testthat/test-get.R @@ -111,6 +111,25 @@ test_that("used functions returned correctly when file doesn't contain all token expect_identical(get_used_functions(filename), expected) }) +test_that("get_library correctly 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") + + 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") From 3f1516aa8eeb9514c39cb3cba836db6f1b98d156 Mon Sep 17 00:00:00 2001 From: nicholas-masel Date: Sat, 28 Jan 2023 14:56:31 -0500 Subject: [PATCH 2/6] add lsf.str to namespace --- NAMESPACE | 1 + R/get.R | 1 + 2 files changed, 2 insertions(+) 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/R/get.R b/R/get.R index 8b4db92..01d858b 100644 --- a/R/get.R +++ b/R/get.R @@ -211,6 +211,7 @@ get_used_functions <- function(file){ #' @importFrom dplyr mutate #' @importFrom rlang .data #' @importFrom purrr map +#' @importFrom utils lsf.str #' #' @return tibble that includes `library` #' From 64932c9aea56b7df7ff55c1512453ef3340547eb Mon Sep 17 00:00:00 2001 From: nicholas-masel Date: Sat, 28 Jan 2023 15:04:52 -0500 Subject: [PATCH 3/6] clean up attach in test --- tests/testthat/test-get.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-get.R b/tests/testthat/test-get.R index 0b92fbe..9df6a5b 100644 --- a/tests/testthat/test-get.R +++ b/tests/testthat/test-get.R @@ -121,6 +121,7 @@ test_that("get_library correctly returns correct function when a non-function actual <- get_library(tibble(function_name = "search", SYMBOL_PACKAGE = NA)) unlink("dummy.R") + detach("dummy") expected <- tibble::tribble( ~function_name, ~ SYMBOL_PACKAGE, ~library, From 123c72176b9936731c70e75a43f12f7a1d6a451b Mon Sep 17 00:00:00 2001 From: Nicholas Masel Date: Mon, 30 Jan 2023 16:54:41 +0000 Subject: [PATCH 4/6] Examples fail during build --- R/get.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index 01d858b..4fc4924 100644 --- a/R/get.R +++ b/R/get.R @@ -223,8 +223,14 @@ get_library <- function(df){ intersect(ls(.x), lsf.str(.x)) } - search_lookup <- map(search(), functions_only) - names(search_lookup) <- search() + # do not search CheckExEnv, this is created while examples are executed + # T and F as given a delayedAssign, and when we check this environments + # objects, the promise for T and F are evaluated, and return a + # 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 %>% From 029de52c33420eac9f4b4081fb984f67fc6cff68 Mon Sep 17 00:00:00 2001 From: Nicholas Masel Date: Mon, 30 Jan 2023 19:28:08 +0000 Subject: [PATCH 5/6] bump version and add news --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/get.R | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) 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/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 4fc4924..9870557 100644 --- a/R/get.R +++ b/R/get.R @@ -224,8 +224,10 @@ get_library <- function(df){ } # do not search CheckExEnv, this is created while examples are executed - # T and F as given a delayedAssign, and when we check this environments - # objects, the promise for T and F are evaluated, and return a + # 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"] From be518f0d6ebf02445c7943629a15798c4cff81b7 Mon Sep 17 00:00:00 2001 From: Nicholas Masel <61123199+nicholas-masel@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:34:39 -0500 Subject: [PATCH 6/6] Update tests/testthat/test-get.R --- tests/testthat/test-get.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-get.R b/tests/testthat/test-get.R index 9df6a5b..b477174 100644 --- a/tests/testthat/test-get.R +++ b/tests/testthat/test-get.R @@ -111,7 +111,7 @@ test_that("used functions returned correctly when file doesn't contain all token expect_identical(get_used_functions(filename), expected) }) -test_that("get_library correctly returns correct function when a non-function +test_that("get_library returns correct function when a non-function object of same name is available", { writeLines('search <- "dummy object"', "dummy.R")