Fix language:r hook installation when initiated in RStudio by lorenzwalthert · Pull Request #3389 · pre-commit/pre-commit

Closes #3385. The bug is that in install_environment(), the env patch was not applied in the following snippet:

    with _r_code_in_tempfile(r_code_inst_environment) as f:
        cmd_output_b(_rscript_exec(), '--vanilla', f, cwd=env_dir)

The existing _execute_vanilla_r_code_as_script() abstracting away

  1. the application of env patch and
  2. the writing inline code to file and executing there (since inline execution lead to parser failures)

was only suitable to execute R code after the environment has been installed and was for that reason not used when the renv environment was set up initially.
Hence, the approach I took was to factor out _execute_r() that does 1. and 2. and can be parametrised as far as CLI options passed to R go, so it can be used to create the environment itself (_execute_vanilla_r()) and also later to run R code in it (_execute_r_in_renv(), previously named _execute_vanilla_r_code_as_script()).