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

Resolve R CMD check note about 'scales' package #672

Closed
wants to merge 3 commits into from

Conversation

arni-magnusson
Copy link

@arni-magnusson arni-magnusson commented Oct 2, 2024

This pull request resolves a Note raised by R CMD check, moving the scales package from Imports to Suggests.

The scales package is not imported from, so I'm guessing it's not required as an Imports entry. Not a big issue - just trying to keep R CMD check happy :)

@kellijohnson-NOAA
Copy link
Contributor

Thanks @arni-magnusson for the PR. I am not entirely sure why it thinks that we do not need scales because it is used in some {ggplot2} code here

ggplot2::scale_x_date(labels = scales::date_format("%Y-%m-%d")) +

Though we should change to scales::label_date() per the documentation for scales::date_format() but that is a different issue.

I always thought that if a package is used within the code it should be in imports and if it is used by developers say for creating data sets like {usethis} can be in the data-raw folder, then it should be in Suggests. Feel free to correct me if I am wrong.

@arni-magnusson
Copy link
Author

arni-magnusson commented Oct 5, 2024

You're absolutely right. At closer inspection, I can see that the scales package should indeed be in the Imports field of the DESCRIPTION file, not in Suggests.

This Note from R CMD check is effectively a false positive. I hadn't come across this case of false positive from R CMD check before, as I tend to use @importFrom pkg function for functions that I use. I fully appreciate if the FIMS style is not to import every function that is used, following the recommendation in Wickham and Bryan's book on R Packages, section 11.4.1.

Wickham and Bryan point to a workaround solution in their section 11.4.1.1, defining a dummy ignore_unused_imports() function. I've modified the pull request to apply this solution, also used in devtools. Feel free to ignore the pull request if this solution seems clunky :)

An alternative solution pointed out by Wickham and Bryan section 11.4.1.1 would be to add this entry to FIMS-package.R:
#' @importFrom scales date_format

@arni-magnusson arni-magnusson changed the title Move scales package from Imports to Suggests Resolve R CMD check note about 'scales' package Oct 11, 2024
@kellijohnson-NOAA
Copy link
Contributor

@arni-magnusson thank you for your pull request. Upon further investigation, I believe that this is happening because {scales} is used inside of methods::setMethod() and not as standalone code in a normal function. I am going to figure out exactly what call the note is being generated from in devtools::check() so I can report it as a formal issue and then hopefully we will not have to have a workaround. I may implement your current suggestion in dev if we do not get a more permanent solution by the next release. So, I will leave this PR open as a reminder.

Second, all future contributions should be made to dev and not main. This is a new protocol for us as of ~ June so it is not well documented. I will try to fix that.

@kellijohnson-NOAA
Copy link
Contributor

I finally figured it out 😓! Line 169 in the following code is incorrect

FIMS/R/fimsframe.R

Lines 166 to 177 in f0d4e76

setMethod(
f = "plot",
signature = "FIMSFrame",
definition = function(x) {
ggplot2::ggplot(
data = x@data,
mapping = ggplot2::aes(
x = as.Date(.data[["datestart"]]),
y = .data[["value"]],
col = .data[["name"]]
)
) +

It should be

setMethod(
  f = "plot",
  signature = "FIMSFrame",
  definition = function(x, y, ...) {
    ggplot2::ggplot(
      data = x@data,
      mapping = ggplot2::aes(
        x = as.Date(.data[["datestart"]]),
        y = .data[["value"]],
        col = .data[["name"]]
      )
    ) +

because the args(plot) are plot(x, y, ...) and the addition to the generic method needs to have the same arguments or more if ... is present. My original code only has x, which was causing lapply(exprs, deparse), where exprs are all code chunks in the package, to call out the plot method as a .local function rather than a standard function. This later leads to find_bad_exprs() not being able to pick up a package being used in the code chunk. FYI all of this is in R CMD check --as-cran or in tools:::.check_packages_used().

@arni-magnusson let me know if you would like to modify your PR to have proposed fix to dev or I can open a new PR. Thanks again 🙏 for bringing this up. Although, it turned into quite the 🐰 🕳️ it was a fun one.

Below are some references that helped me find some answers.

@arni-magnusson arni-magnusson changed the base branch from main to dev November 12, 2024 02:52
@arni-magnusson
Copy link
Author

Thanks for the investigation and following up, @kellijohnson-NOAA. I've modified the PR to target the dev branch. That was a new button for me to learn about in GitHub :)

kellijohnson-NOAA added a commit that referenced this pull request Dec 5, 2024
For plot to be properly documented and rendered all arguments must be
present in the methods, previously we only had x, which led to scales
not being seen as a package that was needed. Now that y and ... have
been added the package is compiling without the error noted by

Part of #671
Close the PR #672, which is no longer needed with this commit. The
methods proposed in #672 was a work around where this commit fixes the
problem.
@kellijohnson-NOAA kellijohnson-NOAA mentioned this pull request Dec 5, 2024
kellijohnson-NOAA added a commit that referenced this pull request Dec 5, 2024
For plot to be properly documented and rendered all arguments must be
present in the methods, previously we only had x, which led to scales
not being seen as a package that was needed. Now that y and ... have
been added the package is compiling without the error noted by

Part of #671
Close the PR #672, which is no longer needed with this commit. The
methods proposed in #672 was a work around where this commit fixes the
problem.
@kellijohnson-NOAA
Copy link
Contributor

@arni-magnusson thank you for this PR I have fixed it in a20b806 with a slightly different method than what you outlined and I described it above. The warning is now taken care of. Thank you again for the contributions and bringing it to my attention.

@kellijohnson-NOAA kellijohnson-NOAA added kind: refactor Restructure code to improve the implementation of FIMS P3 low priority task theme: code cleanup labels Dec 5, 2024
@kellijohnson-NOAA kellijohnson-NOAA added this to the Q2 milestone Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: refactor Restructure code to improve the implementation of FIMS P3 low priority task theme: code cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants