Comments (11)
Thanks for the report. Is Rscript
on your PATH
?
from precommit.
Also see #441 (comment).
from precommit.
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.
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.
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.
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.
@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.
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.
How can you reliably detect if a directory uses a conda environment? And how to find the R executable?
from precommit.
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.
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)
- Allow alternative spellcheck dictionary files HOT 9
- xfun-0.40 fails to build under Windows HOT 3
- Use frozen PPM snapshots
- specific package not available from MRAN - what would be the next step? HOT 4
- Failure with dev (now CRAN) roxygen2 HOT 1
- Convoluted hook testing infra
- Failure with dev pkgdown HOT 5
- New hook: parsable-roxygen HOT 2
- Integration test hook dependency test fails on R 4.4
- `pip install pre-commit --user` gives error in CI on macOS
- Changing the R version breaks the pre-commit cache
- Add `.qmd` files to lintr hook
- Parallel execution of `style-files` hook causes race condition in styler `.onLoad` function HOT 1
- Use `spelling::update_wordlist()` instead of custom logic to update the wordlist for spell check
- Environment setup fails due to a hardcoded snapshot RSPM link in renv.lock HOT 6
- Failure with recently released pkgdown HOT 1
- How do I wrap markdown in my .qmd files? HOT 5
- Reduce CRAN check time for Windows HOT 1
- Check roxygen code example as well with deps-in-desc hook
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from precommit.