From 96d90a7563513ac2c559225c039126dd67df546b Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 3 Jul 2023 16:24:24 +0000 Subject: [PATCH 1/4] Revert "Merge branch '140-feature-request-create-unit-test-for-rmd-files' into dev" This reverts commit df6eb4d49a25346774152a5a47d08a6cc98360e2, reversing changes made to 9ae9814fbd9a4d11d167ceb6a0b06ce30e804c7e. --- R/get.R | 7 ------- R/interact.R | 15 +-------------- R/log.R | 2 +- R/writer.R | 9 ++------- tests/testthat/test-writer.R | 2 +- 5 files changed, 5 insertions(+), 30 deletions(-) diff --git a/R/get.R b/R/get.R index 4ab8830..92f4ec7 100644 --- a/R/get.R +++ b/R/get.R @@ -155,13 +155,6 @@ get_masked_functions <- function(){ #' get_used_functions <- function(file){ - if (grepl("*.Rmd$", file, ignore.case = TRUE)){ - tmpfile <- tempfile(fileext = ".R") - on.exit(unlink(tmpfile)) - knitr::purl(file, tmpfile) - file <- tmpfile - } - # catch error retfun <- safely(parse, quiet = FALSE, diff --git a/R/interact.R b/R/interact.R index 5852004..959d052 100644 --- a/R/interact.R +++ b/R/interact.R @@ -110,13 +110,6 @@ set_log_name_path <- function(log_name = NA, log_path = NA) { #' @noRd run_safely <- function(file) "dummy" -#' Is this a R Markdown file#' -#' @param file String. Path to file to execute -#' @noRd -is_rmarkdown <- function(file) { - grepl("*.Rmd$", file, ignore.case = TRUE) -} - #' Dummy function for running a file #' @noRd run_file <- function(file){ @@ -125,13 +118,7 @@ run_file <- function(file){ } else{ exec_env <- getOption("log.rx.exec.env") } - - if (is_rmarkdown(file)) { - rmarkdown::render(file, envir = exec_env) - } else ( - source(file, local = exec_env) - ) - + source(file, local = exec_env) } #' Safely run an R script and record results, outputs, messages, errors, warnings diff --git a/R/log.R b/R/log.R index b420b73..7e10223 100644 --- a/R/log.R +++ b/R/log.R @@ -276,7 +276,7 @@ log_write <- function(file = NA, } if ("result" %in% to_report){ cleaned_log_vec <- c(cleaned_log_vec, - write_result(file)) + write_result()) } cleaned_log_vec <- c(cleaned_log_vec, diff --git a/R/writer.R b/R/writer.R index 2b5268b..f10ac82 100644 --- a/R/writer.R +++ b/R/writer.R @@ -255,19 +255,14 @@ write_output <- function() { #' Format result attribute for writing #' -#' @param file String. Path to file to execute #' @return A formatted vector of results #' #' @noRd #' -write_result <- function(file) { +write_result <- function() { result <- get_log_element("result") - if (is_rmarkdown(file)) { - c("\nResult:", paste0("\t", capture.output(result))) - } else { - c("\nResult:", paste0("\t", capture.output(result$value))) - } + c("\nResult:", paste0("\t", capture.output(result$value))) } #' Format lint results for writing diff --git a/tests/testthat/test-writer.R b/tests/testthat/test-writer.R index 2ff04e3..dcd6d98 100644 --- a/tests/testthat/test-writer.R +++ b/tests/testthat/test-writer.R @@ -176,7 +176,7 @@ test_that("write_result will return a formatted log result element", { run_safely_loudly(fp) - expect_identical(write_result(fp), + expect_identical(write_result(), c("\nResult:", paste0("\t", capture.output(data.frame(test = c(8, 6, 7, 5, 3, 0, 9)))))) log_remove() From b47c7d31404eae8b9f326480dfe04180993d5861 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 3 Jul 2023 16:26:33 +0000 Subject: [PATCH 2/4] Revert "resolve conflict" This reverts commit ce6a9d0cd55dbf282ff50c8245bff19ee0deeb06. --- R/get.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/get.R b/R/get.R index 92f4ec7..4a79b03 100644 --- a/R/get.R +++ b/R/get.R @@ -199,6 +199,10 @@ get_used_functions <- function(file){ select(all_of(c("function_name", "library"))) %>% distinct() + # distinct_use[is.na(distinct_use)] <- "!!! NOT FOUND !!!" + # + # distinct_use + } From 6afe6c4c6e5739ea3d3b7acc381f78576bdb696b Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 3 Jul 2023 16:26:43 +0000 Subject: [PATCH 3/4] Revert "resolve conflict" This reverts commit 858ff84c697be0115be78745afb793019c485bc3. --- R/get.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/get.R b/R/get.R index 4a79b03..385eb0e 100644 --- a/R/get.R +++ b/R/get.R @@ -195,13 +195,13 @@ get_used_functions <- function(file){ mutate(function_name = coalesce(.data[["SYMBOL_FUNCTION_CALL"]], .data[["SPECIAL"]])) - get_library(combine_tokens) %>% - select(all_of(c("function_name", "library"))) %>% - distinct() + distinct_use <- get_library(combine_tokens) %>% + select(.data$function_name, .data$library) %>% + distinct(across()) - # distinct_use[is.na(distinct_use)] <- "!!! NOT FOUND !!!" - # - # distinct_use + distinct_use[is.na(distinct_use)] <- "!!! NOT FOUND !!!" + + distinct_use } From 582878cf6dd96304874f5148d74626fc2f1d46f1 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 6 Jul 2023 12:04:01 -0400 Subject: [PATCH 4/4] Update R/get.R Co-authored-by: Nicholas Masel <61123199+nicholas-masel@users.noreply.github.com> --- R/get.R | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/R/get.R b/R/get.R index 385eb0e..12d9884 100644 --- a/R/get.R +++ b/R/get.R @@ -195,13 +195,9 @@ get_used_functions <- function(file){ mutate(function_name = coalesce(.data[["SYMBOL_FUNCTION_CALL"]], .data[["SPECIAL"]])) - distinct_use <- get_library(combine_tokens) %>% - select(.data$function_name, .data$library) %>% - distinct(across()) - - distinct_use[is.na(distinct_use)] <- "!!! NOT FOUND !!!" - - distinct_use +get_library(combine_tokens) %>% + select(all_of(c("function_name", "library"))) %>% + distinct() }