Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 committed Sep 28, 2023
2 parents be1b015 + a2e514e commit 81b83dc
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 1,053 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ jobs:
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: ubuntu-20.04, r: '4.1', repos: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: '4.2', repos: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: '3.5', repos: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: '3.6', repos: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/spellcheck.yaml

This file was deleted.

13 changes: 4 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: logrx
Title: A Logging Utility Focus on Clinical Trial Programming Workflows
Version: 0.3.0
Version: 0.2.2
Authors@R:
c(
person(given = "Nathan",
Expand Down Expand Up @@ -54,8 +54,7 @@ Imports:
waiter,
tibble,
digest,
lifecycle,
methods
lintr
Suggests:
testthat (>= 3.0.0),
knitr,
Expand All @@ -65,12 +64,8 @@ Suggests:
pkgdown,
Tplyr,
haven,
lintr,
xml2,
here,
readr,
tidyselect
here
VignetteBuilder: knitr
Config/testthat/edition: 3
Depends:
R (>= 4.0.0)
R (>= 3.5.0)
9 changes: 1 addition & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export(log_config)
export(log_init)
export(log_remove)
export(log_write)
export(read_log_file)
export(write_log_header)
export(write_unapproved_functions)
export(write_used_functions)
Expand All @@ -16,9 +15,9 @@ importFrom(dplyr,distinct)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,mutate)
importFrom(dplyr,rename_with)
importFrom(dplyr,select)
importFrom(dplyr,ungroup)
importFrom(lintr,lint)
importFrom(magrittr,"%>%")
importFrom(miniUI,gadgetTitleBar)
importFrom(miniUI,miniContentPanel)
Expand Down Expand Up @@ -52,20 +51,14 @@ importFrom(shiny,uiOutput)
importFrom(stats,aggregate)
importFrom(stringi,stri_wrap)
importFrom(stringr,str_c)
importFrom(stringr,str_count)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(stringr,str_remove)
importFrom(stringr,str_remove_all)
importFrom(stringr,str_replace)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_starts)
importFrom(stringr,str_trim)
importFrom(tibble,tibble)
importFrom(tidyr,all_of)
importFrom(tidyr,complete)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,separate)
importFrom(utils,capture.output)
importFrom(utils,getParseData)
importFrom(utils,lsf.str)
Expand Down
13 changes: 0 additions & 13 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@

# logrx 0.3.0

- Moved website theme to bootstrap 5, enabled search (#179)
- Add `show_repo_url` option in `axecute()` to capture repo URL(s) into log file (#167)
- Moved website theme to Bootstrap 5, enabled search (#179)
- Add `include_rds` argument to `axecute()` to export log as rds file
- Add `read_log_file()` to read logrx log file as optional function
- Add `library_call_linter()` to ensure all library calls are at the top of the script (#163)
- Remove argument for remove_log_object from `axecute()` still accessible via `log_write()` (#182)
- Added functionality so `axecute()` works with `.Rmd` files (#140)
- R Version switched from `>3.5` to `>4.0` in `DESCRIPTION` file (#198)

# logrx 0.2.2

- Hotfix to remove unnecessary `across()` and update `.data$var` top new syntax to match updates in source packages (#172)
Expand Down
35 changes: 6 additions & 29 deletions R/axecute.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
#' @param file String. Path to file to execute
#' @param log_name String. Name of log file
#' @param log_path String. Path to log file
#' @param include_rds Boolean. Option to export log object as Rds file.
#' Defaults to FALSE
#' @param remove_log_object Boolean. Should the log object be removed after
#' writing the log file? Defaults to TRUE
#' @param quit_on_error Boolean. Should the session quit with status 1 on error?
#' Defaults to TRUE
#' @param to_report String vector. Objects to optionally report, may include as
#' many as necessary:
#' * messages: any messages generated by program execution
#' * output: any output generated by program execution
#' * result: any result generated by program execution
#' @param show_repo_url Boolean. Should the repository URLs be reported
#' Defaults to FALSE
#' @param ... Not used
#'
#' @importFrom purrr map_chr
#'
Expand All @@ -34,29 +31,13 @@
#' close(fileConn)
#'
#' axecute(file.path(dir, "hello.R"))
#'
#'
#' fileConn <- file(file.path(dir, "hello.Rmd"))
#' writeLines(text, fileConn)
#' close(fileConn)
#'
#' axecute(file.path(dir, "hello.Rmd"))
axecute <- function(file, log_name = NA,
log_path = NA,
include_rds = FALSE,
remove_log_object = TRUE,
quit_on_error = TRUE,
to_report = c("messages", "output", "result"),
show_repo_url = FALSE,
...){
# deprecations
if (methods::hasArg(remove_log_object)) {
lifecycle::deprecate_stop("0.3.0", "axecute(remove_log_object = )", "axecute(include_rds = )")
}

# remove log object
remove_log_object <- TRUE
to_report = c("messages", "output", "result")){

# lower everything for consistency and check values
# lower everything for consistency and check values
to_report <- map_chr(to_report, tolower)
match.arg(to_report, several.ok = TRUE)

Expand All @@ -70,11 +51,7 @@ axecute <- function(file, log_name = NA,
any_errors <- get_log_element("errors")

# write log
log_write(file = file,
remove_log_object = remove_log_object,
show_repo_url = show_repo_url,
include_rds = include_rds,
to_report = to_report)
log_write(file = file, remove_log_object = remove_log_object, to_report = to_report)

# if error, quit with status = 1 if not interactive
if(!interactive() & !is.null(any_errors) & quit_on_error) {
Expand Down
50 changes: 6 additions & 44 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ get_file_path <- function(file = NA, normalize = TRUE){
#' @noRd
#'
get_session_info <- function(){
return(session_info(info = "all"))
return(capture.output(session_info(info = "all")))
}


Expand Down Expand Up @@ -155,16 +155,6 @@ get_masked_functions <- function(){
#'
get_used_functions <- function(file){

# if markdown, write R code, including inline, to a script
# use this script to find functions used
if (grepl("*.Rmd$", file, ignore.case = TRUE)){
tmpfile <- tempfile(fileext = ".R")
on.exit(unlink(tmpfile))
withr::local_options(list(knitr.purl.inline = TRUE))
knitr::purl(file, tmpfile)
file <- tmpfile
}

# catch error
retfun <- safely(parse,
quiet = FALSE,
Expand Down Expand Up @@ -201,24 +191,14 @@ get_used_functions <- function(file){
names_from = "token") %>%
ungroup()

# if package is present, but symbol or special is not, a function did not follow the ::
# ex. knitr::opts_chunk$set()
# for this case, remove row that contains the package
# set will still be captured but we will be able to link it to a package in this current version
wide_tokens_wo_orphans <- wide_tokens[!(!is.na(wide_tokens$SYMBOL_PACKAGE) & is.na(wide_tokens$SYMBOL_FUNCTION_CALL) & is.na(wide_tokens$SPECIAL)),]

combine_tokens <- wide_tokens_wo_orphans %>%
combine_tokens <- wide_tokens %>%
mutate(function_name = coalesce(.data[["SYMBOL_FUNCTION_CALL"]],
.data[["SPECIAL"]]))

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

distinct_use[is.na(distinct_use)] <- "!!! NOT FOUND !!!"

distinct_use

}


Expand Down Expand Up @@ -298,33 +278,15 @@ get_unapproved_use <- function(approved_packages, used_packages) {
#'
#' @param file File path of file being run
#'
#' @importFrom lintr lint
#'
#' @return results from `lintr::lint()`
#'
#' @noRd
#'
get_lint_results <- function(file) {

if (!requireNamespace("lintr", quietly = TRUE)) {
message(strwrap("Linting will not be included in the log. Install the
lintr package to use the log.rx.lint feature.",
prefix = " ", initial = ""))
return()
}

# lint file if option is turned on
if (!is.logical(getOption('log.rx.lint'))) {
lintr::lint(file, getOption('log.rx.lint'))
lint(file, getOption('log.rx.lint'))
}
}

#' Get repository URLs
#'
#' Obtain repository URLs possibly used to install packages in session
#'
#' @return results from `getOption("repos")` as list
#'
#' @noRd
#'
get_repo_urls <- function() {
as.list(getOption("repos"))
}
17 changes: 2 additions & 15 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 All @@ -152,7 +139,7 @@ run_safely_loudly <- function(file) {
set_log_element("result", ret$result$result)
set_log_element("warnings", ret$warnings)
set_log_element("errors", ret$result$error)
set_log_element("hash_sum", digest::sha1(readLines(file, warn = FALSE)))
set_log_element("hash_sum", digest::sha1(readLines(file)))

# Session Info
set_log_element("session_info", get_session_info())
Expand Down
Loading

0 comments on commit 81b83dc

Please sign in to comment.