Skip to content

Commit

Permalink
Merge pull request #191 from pharmaverse/rewind_dev
Browse files Browse the repository at this point in the history
Rewind dev
  • Loading branch information
bms63 authored Jul 6, 2023
2 parents df6eb4d + 582878c commit 653b0b0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 31 deletions.
9 changes: 1 addition & 8 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -202,7 +195,7 @@ get_used_functions <- function(file){
mutate(function_name = coalesce(.data[["SYMBOL_FUNCTION_CALL"]],
.data[["SPECIAL"]]))

get_library(combine_tokens) %>%
get_library(combine_tokens) %>%
select(all_of(c("function_name", "library"))) %>%
distinct()

Expand Down
15 changes: 1 addition & 14 deletions R/interact.R
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/log.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 2 additions & 7 deletions R/writer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-writer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 653b0b0

Please sign in to comment.