Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #163, #202 #197

Conversation

nicholas-masel
Copy link
Collaborator

@nicholas-masel nicholas-masel commented Aug 4, 2023

Thank you for your Pull Request!

We have developed a Pull Request template to aid you and our reviewers. Completing the below tasks helps to ensure our reviewers can maximize their time on your code as well as making sure the logrx codebase remains robust and consistent.

The spirit of logrx

While many packages to facilitate the logging of code already exist in the R ecosystem, it is hard to find a solution that works well for clinical programming applications. Many logging implementations are more implicit and rely on user input to create the log for the execution of a script. While this is useful for logging specific events of an application, in clinical programming a log has a set purpose.

logrx is built around the concept of creating a log for the execution of an R script that provides an overview of what happened as well as the environment that it happened in. We set out to create a flexible logging utility that could provide the necessary information to anyone reviewing the code execution so they can recreate the execution environment and run the code for themselves. Please make sure your Pull Request meets this spirit of logrx.

Please check off each taskbox as an acknowledgment that you completed the task. This checklist is part of the Github Action workflows and the Pull Request will not be merged into the dev branch until you have checked off each task.

  • The spirit of logrx is met in your Pull Request
  • Check that your Pull Request is targeting the dev branch, Pull Requests to master should use the Release Pull Request Template
  • Code is formatted according to the tidyverse style guide
  • Updated relevant unit tests or have written new unit tests. Remember to remove any configured log objects at the end of every test using log_remove().
  • Creation/updates to relevant roxygen headers and examples.
  • Run devtools::document() so all .Rd files in the man folder and the NAMESPACE file in the project root are updated appropriately
  • Run pkgdown::build_site() and check that all affected examples are displayed correctly and that all new functions occur on the "Reference" page.
  • Update NEWS.md if the changes pertain to a user-facing function (i.e. it has an @export tag) or documentation aimed at users (rather than developers)
  • Address any updates needed for vignettes and/or templates
  • Run R CMD check locally and address all errors and warnings - devtools::check()
  • Link the issue so that it closes after successful merging.
  • Address all merge conflicts and resolve appropriately
  • Pat yourself on the back for a job well done! Much love to your accomplishment!

@nicholas-masel
Copy link
Collaborator Author

I'll update based on our conversation to change the default lint to library_call_linter()

@nicholas-masel nicholas-masel changed the title Closes #163 Closes #163, #202 Aug 30, 2023
# 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'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need :: if we have the function imported?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with leaving them in - we just haven't done a lot of :: in the past. I'm alway unclear what is the best practice.

Copy link
Collaborator Author

@nicholas-masel nicholas-masel Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here was the thought process for using ::. We no longer import the function to remove the dependency on lintr. So instead we warn users if they don't have lintr installed, using requireNamespaces() to check, and use lintr:: instead of attaching the package with require() to avoid unexpected changes to a users search path.

This was based on the second paragraph in the guidance here, https://cran.r-project.org/doc/manuals/R-exts.html#Suggested-packages.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that makes sense!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For packages that are not depends/imports, you need to use the package::function notation. @nicholas-masel is right that you wouldn't want to use require since it changes the environment (loading the package into the search path).

I also suggest naming the arguments just to make sure nothing gets mixed up.

Suggested change
lintr::lint(file, getOption('log.rx.lint'))
lintr::lint(filename = file, linters = getOption('log.rx.lint'))

#' linters = library_call_linter()
#' )
#'
#' # okay
Copy link
Collaborator

@bms63 bms63 Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' # okay
#' # Will pass lint checks

#' @examples
#' library(lintr)
#'
#' # will produce lints
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' # will produce lints
#' # Will fail lint checks

Copy link
Collaborator

@bms63 bms63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty fantastic to me!!! @thebioengineer does this assuage the remotes issue?

Copy link
Collaborator

@thebioengineer thebioengineer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some initial comments here on the code itself. Not tested it locally.

prefix = " ", initial = ""))
return()
}

# lint file if option is turned on
if (!is.logical(getOption('log.rx.lint'))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!is.logical(getOption('log.rx.lint'))) {
if (!is.logical(getOption('log.rx.lint'))) {

Are you expecting the person to pass a viable lintr option? If so, maybe checking more explicitly rather than just if the option is not a boolean would be more reliable. something like is.list(getOption('log.rx.lint')) since it does get passed to lintr::lint as the linters?

Comment on lines +287 to +293
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()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to within the if statement below. Not having lintr has no impact unless the choice is to try to lint if htat makes sense

# 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'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For packages that are not depends/imports, you need to use the package::function notation. @nicholas-masel is right that you wouldn't want to use require since it changes the environment (loading the package into the search path).

I also suggest naming the arguments just to make sure nothing gets mixed up.

Suggested change
lintr::lint(file, getOption('log.rx.lint'))
lintr::lint(filename = file, linters = getOption('log.rx.lint'))

@bms63 bms63 merged commit 1962368 into dev Sep 8, 2023
5 of 7 checks passed
@bms63 bms63 deleted the 163-feature-request-consider-mandatory-lint-for-library-calls-to-be-at-top-of-script branch September 8, 2023 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants