lorenzwalthert / precommit

pre-commit hooks for R projects
https://lorenzwalthert.github.io/precommit/
GNU General Public License v3.0
253 stars 48 forks source link

Error when using R CMD CHECK in rstudio #377

Closed MarkMc1089 closed 2 years ago

MarkMc1089 commented 2 years ago

Further to #376 which I raised after running the check with {renv} activated, I just tried running the check with {renv} deactivated. But I get the error below:

-- R CMD check results ---------------------------------------------------- precommit 0.2.2.9019 ----
Duration: 9.8s

> checking whether package 'precommit' can be installed ... ERROR
  See below...

-- Install failure ----------------------------------------------------------------------------------

* installing *source* package 'precommit' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
Error: package or namespace load failed for 'precommit' in library.dynam(lib, package, package.lib):
 DLL 'magrittr' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/RProjects/precommit.Rcheck/precommit'

1 error x | 0 warnings v | 0 notes v
Error: R CMD check found ERRORs
Execution halted

Exited with status 1.

I definitely have {magrittr} installed (v2.0.2). I'm running on Windows 10 btw.

lorenzwalthert commented 2 years ago

Then please do

library(magrittr)
remotes::install_github("lorenzwalthert/precommit", dependencies = FALSE)
library(precommit)
MarkMc1089 commented 2 years ago

I tried that, but the same error is happening just trying to install it:

> library(magrittr)
> remotes::install_github("lorenzwalthert/precommit", dependencies = FALSE)
Downloading GitHub repo lorenzwalthert/precommit@HEAD
√  checking for file 'C:\Users\Mark\AppData\Local\Temp\RtmpmeWJwO\remotes358c2b9a5792\lorenzwalthert-precommit-874823c/DESCRIPTION' ... 
-  preparing 'precommit': (873ms)
√  checking DESCRIPTION meta-information ... 
-  checking for LF line-endings in source and make files and shell scripts
-  checking for empty or unneeded directories
-  building 'precommit_0.2.2.9010.tar.gz'

Installing package into ‘C:/Users/Mark/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
* installing *source* package 'precommit' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'precommit'
    finding HTML links ... done
    autoupdate                              html  
    call_and_capture                        html  
    call_precommit                          html  
    copy_artifacts                          html  
    diff_requires_run_roxygenize            html  
    dirs_R.cache                            html  
    ensure_named                            html  
    extract_diff_root                       html  
    fallback_doc                            html  
    generate_uninstalled_pkg_name           html  
    git_init                                html  
    hook_state_assert                       html  
    hook_state_create                       html  
    install_impl                            html  
    install_precommit                       html  
    local_test_setup                        html  
    may_require_permanent_cache             html  
    not_conda                               html  
    open_config                             html  
    path_derive_precommit_exec              html  
    path_derive_precommit_exec_conda        html  
    path_derive_precommit_exec_impl         html  
    path_derive_precommit_exec_path         html  
    path_derive_precommit_exec_win_python3plus_base
                                            html  
    path_precommit_exec                     html  
    precommit-package                       html  
    precommit_executable_file               html  
    release_complete                        html  
    release_gh                              html  
    rev_read                                html  
    robust_purl                             html  
    roxygen_assert_additional_dependencies
                                            html  
    roxygenize_with_cache                   html  
    run_test                                html  
    run_test_impl                           html  
    set_config_source                       html  
    snippet_generate                        html  
    uninstall_precommit                     html  
    update_impl                             html  
    update_precommit                        html  
    update_rev_in_config                    html  
    use_ci                                  html  
    use_precommit                           html  
    use_precommit_config                    html  
    version_precommit                       html  
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
Error: package or namespace load failed for 'precommit' in library.dynam(lib, package, package.lib):
 DLL 'magrittr' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/Mark/Documents/R/win-library/4.1/precommit'
* restoring previous 'C:/Users/Mark/Documents/R/win-library/4.1/precommit'
Warning message:
In i.p(...) :
  installation of package ‘C:/Users/Mark/AppData/Local/Temp/RtmpmeWJwO/file358c9433299/precommit_0.2.2.9010.tar.gz’ had non-zero exit status
> library(precommit)
Warning message:
package ‘precommit’ was built under R version 4.1.2 

If I run remotes::install_github("lorenzwalthert/precommit", dependencies = TRUE) then it does install, but I get the same error when running R CMD CHECK in a fresh clone of the repo. Any idea what is going wrong?

MarkMc1089 commented 2 years ago

Btw, I don't understand why I would need to have precommit installed just to run R CMD CHECK on the package repo. How should running the code you gave help here?

lorenzwalthert commented 2 years ago

Btw, I don't understand why I would need to have precommit installed just to run R CMD CHECK on the package repo. How should running the code you gave help here?

Because as it says in your log above, checking if the package is installable is part of R CMD Check.

lorenzwalthert commented 2 years ago

I just googled and it seems the problem appeared before, with other packages. Found some things you might want to try:

remove.packages("magrittr")
remotes::install_github("lorenzwalthert/precommit",
  INSTALL_opts = c("--no-multiarch")
)

Or

remotes::install_cran("magrittr",
  INSTALL_opts = c("--no-multiarch")
)

Sorry I can't offer much more help...

MarkMc1089 commented 2 years ago

Awesome, installing magrittr with the no-arch worked! I never found that solution when looking, so thanks for posting it. It turns out you can pass that argument to R CMD CHECK too, useful to know for the future ;)

The package does work fully as far as I have found so far, but just to let you know, some tests were skipped (not_conda was found to be TRUE, even tho I used conda (via reticulate::install_miniconda()) to install the pre-commit framework, and a few tests failed for me (on Windows as mentioned above). Skipped/Failed tests output:

== Skipped tests ===============================================================
* not_conda() is TRUE (3)

== Failed tests ================================================================
-- Failure (test-conda.R:113:7): Can uninstall (userly) ------------------------
`uninstall_precommit(scope = "user", ask = "none", root = tempdir)` did not throw an error.
-- Error (test-conda.R:140:5): can install pre-commit with remote config -------
Error in `assert_is_installed()`: pre-commit is not installed on your system (or we can't find it).

If you have it installed and you know where it is, please set the R option `precommit.executable` to this path so it can be used to perform various pre-commit commands from R. If you think this is a standard location, please open an issue on GitHub so we can auto-detect this location in the future and spare new users some set-up troubles.

If you don't know where the executable is stored, go back to the log output that resulted from the installation of pre-commit for hints. If you found it and you think it's a standard location, please open an issue on GitHub so we can auto-detect this location in the future and spare unexpereienced users some trouble.

In case you are totally lost with these messages, you can most likely solve the problems with just using the conda installation method, see https://lorenzwalthert.github.io/precommit/ for how to do this.
Backtrace:
    x
 1. +-testthat::expect_message(...) at test-conda.R:140:4
 2. | \-testthat:::quasi_capture(enquo(object), label, capture_messages)
 3. |   +-testthat .capture(...)
 4. |   | \-base::withCallingHandlers(...)
 5. |   \-rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
 6. \-precommit::use_precommit(...)
 7.   \-precommit:::assert_is_installed()
 8.     \-rlang::abort(...)
-- Failure (test-conda.R:155:5): fails gracefully when there are ---------------
`use_precommit(...)` threw an error with unexpected message.
Expected match: "stdout: [ERROR] Cowardly refusing to install hooks with `core.hooksPath` set."
Actual message: "pre-commit is not installed on your system (or we can't find it).\n\nIf you have it installed and you know where it is, please set the R option `precommit.executable` to this path so it can be used to perform various pre-commit commands from R. If you think this is a standard location, please open an issue on GitHub so we can auto-detect this location in the future and spare new users some set-up troubles.\n\nIf you don't know where the executable is stored, go back to the log output that resulted from the installation of pre-commit for hints. If you found it and you think it's a standard location, please open an issue on GitHub so we can auto-detect this location in the future and spare unexpereienced users some trouble.\n\nIn case you are totally lost with these messages, you can most likely solve the problems with just using the conda installation method, see https://lorenzwalthert.github.io/precommit/ for how to do this."
Backtrace:
     x
  1. +-withr::with_dir(...) at test-conda.R:155:4
  2. | \-base::force(code)
  3. +-testthat::expect_error(...) at test-conda.R:160:8
  4. | \-testthat:::quasi_capture(...)
  5. |   +-testthat .capture(...)
  6. |   | \-base::withCallingHandlers(...)
  7. |   \-rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  8. \-precommit::use_precommit(...)
  9.   \-precommit:::assert_is_installed()
 10.     \-rlang::abort(...)
-- Failure (test-conda.R:171:7): fails gracefully when reticulate is not available --
`install_precommit()` did not throw an error.
-- Failure (test-conda.R:176:7): can update via conda --------------------------
`with_mock(update_precommit(), `precommit:::assert_reticulate_is_installed` = function(...) NULL)` did not throw an error.
-- Failure (test-exec.R:22:3): Path can be derived for windows Python >= 3.0 ---
path_derive_precommit_exec_win_python3plus_base() is empty.
-- Failure (test-exec.R:23:3): Path can be derived for windows Python >= 3.0 ---
fs::path_file(path_derive_precommit_exec_win()) not equal to precommit_executable_file().
1/1 mismatches
x[1]: ""
y[1]: "pre-commit.exe"

[ FAIL 7 | WARN 0 | SKIP 3 | PASS 168 ]

Also, one Rd is missing a title:

Warning: communicate_captured_call.Rd is missing name/title. Skipping

lorenzwalthert commented 2 years ago

Ok, great.I rely on GitHub Actions to run the tests for the various combinations of installation method and platform, see e.g. https://github.com/lorenzwalthert/precommit/actions/runs/1855665219. From the workflow files in .github/workflows, you can also see that there are env variables that are set for determining if not_conda() (not your actual installation method).

Also, not all tests for test-conda.R are self-containing, i.e. they must be ran when no pre-commit executable is installed and random order does not work within that file (because testing for uninstallation only works if the test before did the installation). I think if GitHub Action passes, we are fine, although testing infra could be improved to make each test self-contained for example.

lorenzwalthert commented 2 years ago

Also, one Rd is missing a title:

Ok, that we could indeed fix.

lorenzwalthert commented 2 years ago

Can we close this?

MarkMc1089 commented 2 years ago

Sure!

MarkMc1089 commented 2 years ago

Closing