2

I have installed the package and miniconda as per instructions but I keep on getting this error the error "Executable C:/PROGRA~1/R/R-42~1.0\bin\Rscript not found". I can use Rscript normally in the terminal.

Version information

pre-commit version: 2.19.0
git --version: git version 2.36.1.windows.1
sys.version:
    3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 05:59:00) [MSC v.1929 64 bit (AMD64)]
sys.executable: C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\python.exe
os.name: nt
sys.platform: win32

Error information

An unexpected error has occurred: CalledProcessError: command: ('C:/PROGRA~1/R/R-42~1.0\\bin\\Rscript', '--vanilla', '-e', '    options(install.packages.compile.from.source = "never")\n                prefix_dir <- \'C:\\\\Users\\\\pinto\\\\.cache\\\\pre-commit\\\\repom0jg06ie\'\n            options(\n                repos = c(CRAN = "https://cran.rstudio.com"),\n                renv.consent = TRUE\n            )\n            source("renv/activate.R")\n            renv::restore()\n            activate_statement <- paste0(\n              \'suppressWarnings({\',\n              \'old <- setwd("\', getwd(), \'"); \',\n              \'source("renv/activate.R"); \',\n              \'setwd(old); \',\n              \'renv::load("\', getwd(), \'");})\'\n            )\n            writeLines(activate_statement, \'activate.R\')\n            is_package <- tryCatch(\n              {\n                  path_desc <- file.path(prefix_dir, \'DESCRIPTION\')\n                  suppressWarnings(desc <- read.dcf(path_desc))\n                  "Package" %in% colnames(desc)\n              },\n              error = function(...) FALSE\n            )\n            if (is_package) {\n                renv::install(prefix_dir)\n            }\n            \n    ')
return code: 1
expected return code: 0
stdout:
    Executable `C:/PROGRA~1/R/R-42~1.0\bin\Rscript` not found
stderr: (none)
Traceback (most recent call last):
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\error_handler.py", line 73, in error_handler
    yield
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\main.py", line 361, in main
    return hook_impl(
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\commands\hook_impl.py", line 238, in hook_impl
    return retv | run(config, store, ns)
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\commands\run.py", line 414, in run
    install_hook_envs(to_install, store)
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\repository.py", line 79, in _hook_install
    lang.install_environment(
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\languages\r.py", line 139, in install_environment
    cmd_output_b(
  File "C:\Users\pinto\AppData\Local\r-miniconda\envs\r-precommit\lib\site-packages\pre_commit\util.py", line 146, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('C:/PROGRA~1/R/R-42~1.0\\bin\\Rscript', '--vanilla', '-e', '    options(install.packages.compile.from.source = "never")\n                prefix_dir <- \'C:\\\\Users\\\\pinto\\\\.cache\\\\pre-commit\\\\repom0jg06ie\'\n            options(\n                repos = c(CRAN = "https://cran.rstudio.com"),\n                renv.consent = TRUE\n            )\n            source("renv/activate.R")\n            renv::restore()\n            activate_statement <- paste0(\n              \'suppressWarnings({\',\n              \'old <- setwd("\', getwd(), \'"); \',\n              \'source("renv/activate.R"); \',\n              \'setwd(old); \',\n              \'renv::load("\', getwd(), \'");})\'\n            )\n            writeLines(activate_statement, \'activate.R\')\n            is_package <- tryCatch(\n              {\n                  path_desc <- file.path(prefix_dir, \'DESCRIPTION\')\n                  suppressWarnings(desc <- read.dcf(path_desc))\n                  "Package" %in% colnames(desc)\n              },\n              error = function(...) FALSE\n            )\n            if (is_package) {\n                renv::install(prefix_dir)\n            }\n            \n    ')
return code: 1
expected return code: 0
stdout:
    Executable `C:/PROGRA~1/R/R-42~1.0\bin\Rscript` not found
stderr: (none)
sessionInfo()
#> R version 4.2.0 (2022-04-22 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19042)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=en_GB.utf8  LC_CTYPE=en_GB.utf8    LC_MONETARY=en_GB.utf8
#> [4] LC_NUMERIC=C           LC_TIME=en_GB.utf8    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] rstudioapi_0.13   knitr_1.39        magrittr_2.0.3    R.cache_0.15.0   
#>  [5] rlang_1.0.2       fastmap_1.1.0     fansi_1.0.3       stringr_1.4.0    
#>  [9] styler_1.7.0      highr_0.9         tools_4.2.0       xfun_0.31        
#> [13] R.oo_1.24.0       utf8_1.2.2        cli_3.3.0         withr_2.5.0      
#> [17] htmltools_0.5.2   ellipsis_0.3.2    yaml_2.3.5        digest_0.6.29    
#> [21] tibble_3.1.7      lifecycle_1.0.1   crayon_1.5.1      purrr_0.3.4      
#> [25] R.utils_2.11.0    vctrs_0.4.1       fs_1.5.2          glue_1.6.2       
#> [29] evaluate_0.15     rmarkdown_2.14    reprex_2.0.1      stringi_1.7.6    
#> [33] compiler_4.2.0    pillar_1.7.0      R.methodsS3_1.8.1 pkgconfig_2.0.3
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
glhrm
  • 51
  • 2

1 Answers1

0

it looks like your R_HOME is set incorrectly to a path which does not exist -- try unsetting that (or correcting it)

pre-commit uses $R_HOME/bin/Rscript as the default location for executing R-based hooks


disclaimer: I wrote pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • I have changed `R_HOME` and keep on getting the same error : "Executable `C:\Program Files\R\R-4.2.0\bin\Rscript` not found" – glhrm Jun 09 '22 at 16:54
  • is the error message correct? does that file not exist? what does `which Rscript` give you? – anthony sottile Jun 09 '22 at 17:10
  • Here is what `which Rscript` gives me `/c/Program Files/R/R-4.2.0/bin/x64/Rscript`, I assume that this x64 is the problem? – glhrm Jun 09 '22 at 17:52
  • does unsetting `R_HOME` work? it should probably pick the default value – anthony sottile Jun 10 '22 at 00:19
  • Unsetting `R_HOME` gives `/c/Program Files/R/R-4.2.0/bin/x64/Rscript` but then I get the old error "Executable `C:/PROGRA~1/R/R-42~1.0\bin\Rscript` not found". I am starting to think its somehow related to R4.2 or Windows. – glhrm Jun 10 '22 at 06:18
  • Discussion on GitHub with potential solution candidates https://github.com/pre-commit/pre-commit/issues/2599 – Lorenz Walthert Dec 12 '22 at 11:11