Giter VIP home page Giter VIP logo

Comments (11)

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

Thanks for the report. Is Rscript on your PATH?

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

Also see #441 (comment).

from precommit.

joshpersi avatar joshpersi commented on July 27, 2024

I honestly don't know how to tell if Rscript is on my PATH.

If I run Sys.getenv("PATH") in RStudio, where precommit works, this is the output (I've broken lines at ; for readability):

C:\\rtools43\\x86_64-w64-mingw32.static.posix\\bin
C:\\rtools43\\usr\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\R\\R-4.3.1\\bin\\x64
C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath
C:\\Oracle\\product\\12.1\\bin
C:\\WINDOWS\\System32
C:\\WINDOWS
C:\\WINDOWS\\System32\\Wbem
C:\\WINDOWS\\System32\\Windowspowershell\\V1.0\\
C:\\WINDOWS\\System32\\Openssh\\
C:\\WINDOWS\\system32
C:\\WINDOWS
C:\\WINDOWS\\System32\\Wbem
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\
C:\\WINDOWS\\System32\\OpenSSH\\
C:\\Program Files\\1E\\Client\\Extensibility\\NomadBranch
C:\\Program Files\\dotnet\\
C:\\Program Files\\Docker\\Docker\\resources\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Quarto\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Microsoft\\WindowsApps
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Git\\cmd
C:\\Users\\joshpersi\\AppData\\Roaming\\TinyTeX\\bin\\win32
C:\\Users\\joshpersi\\AppData\\Local\\Pandoc\\
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Quarto\\bin
C:\\Program Files\\RStudio\\resources\\app\\bin\\postback

And here's what I get if I run Sys.getenv("PATH") in VS Code:

C:\\rtools43/x86_64-w64-mingw32.static.posix/bin
C:\\rtools43/usr/bin
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda\\Library\\mingw-w64\\bin
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda\\Library\\usr\\bin
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda\\Library\\bin
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda\\Scripts
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda\\bin
C:\\Users\\joshpersi\\AppData\\Local\\r-miniconda\\condabin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Git\\mingw64\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Git\\usr\\bin
C:\\Users\\joshpersi\\bin
C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath
C:\\Oracle\\product\\12.1\\bin
C:\\WINDOWS\\System32
C:\\WINDOWS
C:\\WINDOWS\\System32\\Wbem
C:\\WINDOWS\\System32\\Windowspowershell\\V1.0
C:\\WINDOWS\\System32\\Openssh
C:\\WINDOWS\\system32
C:\\WINDOWS
C:\\WINDOWS\\System32\\Wbem
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0
C:\\WINDOWS\\System32\\OpenSSH
C:\\Program Files\\1E\\Client\\Extensibility\\NomadBranch
C:\\Program Files\\dotnet
C:\\Program Files\\Docker\\Docker\\resources\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Quarto\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Microsoft\\WindowsApps
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Git\\cmd
C:\\Users\\joshpersi\\AppData\\Roaming\\TinyTeX\\bin\\win32
C:\\Users\\joshpersi\\AppData\\Local\\Pandoc
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin
C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath
C:\\Oracle\\product\\12.1\\bin
C:\\WINDOWS\\System32
C:\\WINDOWS
C:\\WINDOWS\\System32\\Wbem
C:\\WINDOWS\\System32\\Windowspowershell\\V1.0\\
C:\\WINDOWS\\System32\\Openssh\\
C:\\WINDOWS\\system32
C:\\WINDOWS
C:\\WINDOWS\\System32\\Wbem
C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\
C:\\WINDOWS\\System32\\OpenSSH\\
C:\\Program Files\\1E\\Client\\Extensibility\\NomadBranch
C:\\Program Files\\dotnet\\
C:\\Program Files\\Docker\\Docker\\resources\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Quarto\\bin
C:\\Users\\joshpersi\\AppData\\Local\\Microsoft\\WindowsApps
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Git\\cmd
C:\\Users\\joshpersi\\AppData\\Roaming\\TinyTeX\\bin\\win32
C:\\Users\\joshpersi\\AppData\\Local\\Pandoc\\
C:\\Users\\joshpersi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin

If it's helpful, here are two VS code settings I've manually configured:

"r.rterm.windows": "C:\\Users\\persij\\AppData\\Local\\Programs\\R\\R-4.3.1\\bin\\x64\\R.exe",
"r.rpath.windows": "C:\\Users\\persij\\AppData\\Local\\Programs\\R\\R-4.3.1",

I tried to set the path environment in VS code to be the same as the one in RStudio but to no avail.

Please let me know if there's anything else I can do to help!

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

Ok finding out how Rscript gets ob your PATH is not a pre-commit issue. Does the same problem happen when you open a terminal with Apple‘s terminal app and try to git commit in that repo? I don’t know how you installed R but seems not a common installation avenue…

from precommit.

joshpersi avatar joshpersi commented on July 27, 2024

Thanks for your patience - I now appreciate this isn't a precommit issue. I'll look into it a bit more on my own. Thanks for your help!

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

I think if you use VS Code and a reasonable recent version of macOS, then your default shell is zsh (and there should be no difference to opening a new zsh shell with the Apple terminal app) and you can add the location of your R executable to the PATH by adding it to the respective profile file (there are a few different files that have different behaviour mainly based on how you start the shell).

Or you just install R again with an installation method that places the executable on the PATH, or you symlink the current executable in a place that is already on the PATH.

from precommit.

skwde avatar skwde commented on July 27, 2024

@lorenzwalthert I have the same issue, Rscript is not found.

I basically use two different conda environments, one for pre-commit and another one for R.
Of course Rscript is not available in the pre-commit environment.

To my understanding pre-commit will fetch what is needed on pre-commit run --all.
Why doesn't it fetch Rscript as well?
Isn't that the power of pre-commit to just specify a hook in pre-commit-config.yaml and forget about the setup?

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

Ok. I don't think I accounted for the situation where you don’t have a global R executable but instead only one in a conda environment. In fact, I think this would require a change to the python pre-commit package because when you call git to commit, git calls pre-commit which calls Rscript on the PATH to activate renv to call the hooks. Temporary workaround is to have a global R installation you can fall back on that is on the PATH.

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

How can you reliably detect if a directory uses a conda environment? And how to find the R executable?

from precommit.

skwde avatar skwde commented on July 27, 2024

Ok, the availability of Rscript (and R in general) is a dependency of pre-commit itself and not your hook (https://pre-commit.com/#r). So it makes actually sense to put this along side the pre-commit install (i.e. into the pre-commit environment).

So in that case it would be enough to look for Rscript in the environment where pre-commit is installed.

Regarding your question, does this https://pre-commit.com/#conda help?
I.e. pre-commit supports conda as long as a environment.yml is present.
Hmm I think it would be better though if one can specify a environment.yml to use. Mine are often called something like environment.<name>.yml.

from precommit.

lorenzwalthert avatar lorenzwalthert commented on July 27, 2024

Ok, the availability of Rscript (and R in general) is a dependency of pre-commit itself and not your hook (https://pre-commit.com/#r)

In pre-commit, there are different levels of languages, r is implemented as a second level language. This means that a global R executable is required, but R package dependencies will be managed in an isolated fashion (with {renv}).

So it makes actually sense to put this along side the pre-commit install (i.e. into the pre-commit environment).

Usually though, pre-commit is installed globally (at least I haven't come across a project where pre-commit was listed as a dev requirement), and there is not necessarily a pre-commit conda or venv virtual environment associated with it.

Also note that for example in R, the {renv} environment that pre-commit uses is not same as the user created for his project (if any), but these are separate virtual environments. While most R projects don't use {renv}, some do, and pre-commit's {renv} environment is separate from it. So if you are using conda to manage your project's dependencies, it does not mean that pre-commit has to use conda as well. In fact if you install {precommit} into your conda environment, it is only useful as far as the R API goes, e.g. to precommit::install() or perform other operations from the R console interactively.

Regarding your question, does this https://pre-commit.com/#conda help?

If this repository's hooks were implemented with language: conda instead of language: r (see .pre-commit-hooks.yaml), then probably a global R installation would not be required, yes, because the Rscript executable would be bootstrapped as part of the conda environment. Unfortunately, I think a hook repo (like lorenzwalthert/precommit) can only contain an implementation of one language, so we had to create a second repo to do this.

Summa summarum, I think the easiest is just to install R globally so you can use it for pre-commit. Using the hooks from this repo won't install any packages in your global R package library, except maybe {renv}.

from precommit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.