Skip to content

Conversation

lorenzwalthert
Copy link
Contributor

@lorenzwalthert lorenzwalthert commented Jan 19, 2025

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()).

@lorenzwalthert lorenzwalthert marked this pull request as ready for review January 20, 2025 11:18
@asottile asottile force-pushed the dev-always-unset-renv branch from ffe1692 to c2c061c Compare January 20, 2025 18:10
otherwise, installing the hooks when RENV_USER env variable is set (e.g. in RStudio with renv project) will result in executing the installation script in the wrong renv
Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

@asottile asottile enabled auto-merge January 20, 2025 18:14
@asottile asottile merged commit c3125a4 into pre-commit:main Jan 20, 2025
24 checks passed
@lorenzwalthert lorenzwalthert deleted the dev-always-unset-renv branch January 21, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

pre-commit does not work when used in a project with R renv
2 participants