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

Avoid R package warning in loadSupport() if autoload is disabled #3513

Merged
merged 7 commits into from
Mar 15, 2024

Conversation

krlmlr
Copy link
Contributor

@krlmlr krlmlr commented Sep 29, 2021

in loadSupport(), if _disable_autoload.R exists.

@wch
Copy link
Collaborator

wch commented Sep 29, 2021

@krlmlr Can you provide instructions on how to reproduce the issue?

@krlmlr
Copy link
Contributor Author

krlmlr commented Sep 30, 2021

Create a Shiny app with a package structure (with DESCRIPTION and NAMESPACE files) that contains a file R/_disable_autoload.R and uses e.g. pkgload::load_all() to load the files in R/ . The warning still occurs.

Do we need a test here?

@CLAassistant
Copy link

CLAassistant commented Nov 8, 2023

CLA assistant check
All committers have signed the CLA.

@tanho63
Copy link

tanho63 commented Mar 9, 2024

Minimal code for reproducing bogus warning here:

withr::with_dir(tempdir(check = TRUE),{
  dir.create("R", showWarnings = FALSE)
  # loadSupport documentation suggests adding a blank R/_disable_autoload.R file
  # will disable automatic loading of the R/ files
  file.create("R/_disable_autoload.R")
  # test that code was not loaded by adding a print statement
  writeLines(
    "print('R/ code was sourced')",
    "R/code.R"
  )
  # loadSupport checks for a NAMESPACE file and/or a DESCRIPTION file to determine
  # if the directory contains a package, add NAMESPACE to trigger the check
  file.create("NAMESPACE")
  # add minimal app.R code
  writeLines(
    text = "
    shiny::shinyApp(
      ui = shiny::fluidPage(), 
      server = function(input, output, session) {}
    )
    ", 
    con = "app.R"
  )
  shiny::runApp()
  # still triggers warning, despite not actually running the code in question
})

@krlmlr krlmlr force-pushed the b-load-support-false-positive branch from 2c9ceee to 3cea593 Compare March 11, 2024 08:54
R/shinyapp.R Outdated
Comment on lines 379 to 381
if (length(disabled) > 0){
return(invisible(renv))
}
Copy link

Choose a reason for hiding this comment

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

@krlmlr maybe simpler to move this early exit on disabled to L356 instead of extending the if clause?

Copy link
Member

Choose a reason for hiding this comment

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

I'm working on a change like that... will push back to this PR in a minute.

Copy link
Member

Choose a reason for hiding this comment

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

In the end, I think the warning was happening too early. By moving it down we can instead warn just before evaluating the code in the R/ support directory.

@gadenbuie gadenbuie changed the title Avoid bogus warning Avoid R package warning in loadSupport() if autoload is disabled Mar 11, 2024
@gadenbuie gadenbuie requested a review from wch March 11, 2024 14:47
@gadenbuie gadenbuie added this to the 1.9 milestone Mar 11, 2024
Copy link
Contributor Author

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Nice, thanks for picking this up!

R/shinyapp.R Outdated Show resolved Hide resolved
krlmlr and others added 2 commits March 11, 2024 20:06
@cpsievert cpsievert merged commit ae308e0 into rstudio:main Mar 15, 2024
12 checks passed
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.

6 participants