Skip to content

Commit

Permalink
Merge pull request #214 from pharmaverse/parmsam-pfizer-patch-1
Browse files Browse the repository at this point in the history
add name to DESCRIPTION as author
  • Loading branch information
parmsam-pfizer committed Sep 26, 2023
2 parents 678a34c + b06a80f commit 7964ee3
Show file tree
Hide file tree
Showing 33 changed files with 1,057 additions and 77 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ jobs:
matrix:
config:
- {os: windows-latest, r: 'release'}
- {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: '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: 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: 33 additions & 0 deletions .github/workflows/spellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Spellcheck

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
spell:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
needs: spelling

- name: Run Spelling Check test
uses: insightsengineering/r-spellcheck-action@v3
with:
exclude: data/*
17 changes: 13 additions & 4 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.2.2
Version: 0.3.0
Authors@R:
c(
person(given = "Nathan",
Expand All @@ -23,6 +23,10 @@ Authors@R:
family = "Masel",
email = "nmasel@its.jnj.com",
role = "aut"),
person(given = "Sam",
family = "Parmar",
email = "samir.parmar@pfizer.com",
role = "aut"),
person(given = "GSK/Atorus JPT",
role = c("cph", "fnd"))
)
Expand Down Expand Up @@ -50,7 +54,8 @@ Imports:
waiter,
tibble,
digest,
lintr
lifecycle,
methods
Suggests:
testthat (>= 3.0.0),
knitr,
Expand All @@ -60,8 +65,12 @@ Suggests:
pkgdown,
Tplyr,
haven,
here
lintr,
xml2,
here,
readr,
tidyselect
VignetteBuilder: knitr
Config/testthat/edition: 3
Depends:
R (>= 3.5.0)
R (>= 4.0.0)
9 changes: 8 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 @@ -15,9 +16,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 @@ -51,14 +52,20 @@ 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: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@

# 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: 29 additions & 6 deletions R/axecute.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
#' @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 remove_log_object Boolean. Should the log object be removed after
#' writing the log file? Defaults to TRUE
#' @param include_rds Boolean. Option to export log object as Rds file.
#' Defaults to FALSE
#' @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 @@ -31,13 +34,29 @@
#' 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,
remove_log_object = TRUE,
include_rds = FALSE,
quit_on_error = TRUE,
to_report = c("messages", "output", "result")){
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

# 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 @@ -51,7 +70,11 @@ axecute <- function(file, log_name = NA,
any_errors <- get_log_element("errors")

# write log
log_write(file = file, remove_log_object = remove_log_object, to_report = to_report)
log_write(file = file,
remove_log_object = remove_log_object,
show_repo_url = show_repo_url,
include_rds = include_rds,
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: 44 additions & 6 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(capture.output(session_info(info = "all")))
return(session_info(info = "all"))
}


Expand Down Expand Up @@ -155,6 +155,16 @@ 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 @@ -191,14 +201,24 @@ get_used_functions <- function(file){
names_from = "token") %>%
ungroup()

combine_tokens <- wide_tokens %>%
# 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 %>%
mutate(function_name = coalesce(.data[["SYMBOL_FUNCTION_CALL"]],
.data[["SPECIAL"]]))

get_library(combine_tokens) %>%
distinct_use <- 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 @@ -278,15 +298,33 @@ 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'))) {
lint(file, getOption('log.rx.lint'))
lintr::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: 15 additions & 2 deletions R/interact.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ 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 @@ -118,7 +125,13 @@ run_file <- function(file){
} else{
exec_env <- getOption("log.rx.exec.env")
}
source(file, local = exec_env)

if(is_rmarkdown(file)){
rmarkdown::render(file, envir = exec_env)
} else{
source(file, local = exec_env)
}

}

#' Safely run an R script and record results, outputs, messages, errors, warnings
Expand All @@ -139,7 +152,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)))
set_log_element("hash_sum", digest::sha1(readLines(file, warn = FALSE)))

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

0 comments on commit 7964ee3

Please sign in to comment.