lorenzwalthert / precommit

pre-commit hooks for R projects
https://lorenzwalthert.github.io/precommit/
GNU General Public License v3.0
252 stars 48 forks source link

Error: Unknown or uninitialised column: `text`. #246

Closed njtierney closed 3 years ago

njtierney commented 3 years ago

When running precommit I get this message:

❯ git commit
style-files..............................................................Failed
- hook id: style-files
- exit code: 1

Styling  3  files:
 R/extract_replace_combine.R                   ✔ 
 tests/testthat/test_extract_replace_combine.R Error: Unknown or uninitialised column: `text`.
Execution halted

roxygenize...............................................................Passed
use-tidy-description.................................(no files to check)Skipped
spell-check..........................................(no files to check)Skipped
lintr....................................................................Passed
readme-rmd-rendered..................................(no files to check)Skipped
parsable-R...............................................................Passed
no-browser-statement.....................................................Passed
deps-in-desc.............................................................Passed
Check for added large files..............................................Passed
Fix End of Files.........................................................Passed
Don't commit common R artifacts......................(no files to check)Skipped

here is the precommit info

# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
-   repo: https://github.com/lorenzwalthert/precommit
    rev: v0.1.3
    hooks: 
    -   id: style-files
        args: [--style_pkg=styler, --style_fun=tidyverse_style]    
    -   id: roxygenize
    # codemeta must be above use-tidy-description when both are used
    # -   id: codemeta-description-updated
    -   id: use-tidy-description
    -   id: spell-check
        exclude: >
          (?x)^(
          data/.*| 
          (.*/|)\.Rprofile|
          (.*/|)\.Renviron|
          (.*/|)\.gitignore|
          (.*/|)NAMESPACE|
          (.*/|)WORDLIST|
          (.*/|)\.travis.yml|
          (.*/|)appveyor.yml|
          (.*/|)\.Rbuildignore|
          (.*/|)\.pre-commit-.*|
          .*\.[rR]|
          .*\.Rproj|
          .*\.py|
          .*\.feather|
          .*\.rds|
          .*\.Rds|
          .*\.sh|
          .*\.RData
          )$
    -   id: lintr
    -   id: readme-rmd-rendered
    -   id: parsable-R
    -   id: no-browser-statement
    -   id: deps-in-desc
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.4.0
    hooks: 
    -   id: check-added-large-files
        args: ['--maxkb=200']
    -   id: end-of-file-fixer
        exclude: '\.Rd'
-   repo: local
    hooks:
    -   id: forbid-to-commit
        name: Don't commit common R artifacts
        entry: Cannot commit .Rhistory, .RData, .Rds or .rds.
        language: fail
        files: '\.Rhistory|\.RData|\.Rds|\.rds$'
        # `exclude: <regex>` to allow committing specific files.

and my sessioninfo

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.5 (2021-03-31) #> os macOS Big Sur 10.16 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Perth #> date 2021-05-05 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> backports 1.2.1 2020-12-09 [1] standard (@1.2.1) #> cli 2.4.0 2021-04-05 [1] CRAN (R 4.0.2) #> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.2) #> digest 0.6.27 2020-10-24 [1] standard (@0.6.27) #> ellipsis 0.3.1 2020-05-15 [1] standard (@0.3.1) #> evaluate 0.14 2019-05-28 [1] standard (@0.14) #> fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.2) #> fs 1.5.0 2020-07-31 [1] standard (@1.5.0) #> glue 1.4.2 2020-08-27 [1] standard (@1.4.2) #> highr 0.8 2019-03-20 [1] standard (@0.8) #> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2) #> knitr 1.31 2021-01-27 [1] CRAN (R 4.0.2) #> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.2) #> magrittr 2.0.1 2020-11-17 [1] standard (@2.0.1) #> pillar 1.6.0 2021-04-13 [1] CRAN (R 4.0.2) #> pkgconfig 2.0.3 2019-09-22 [1] standard (@2.0.3) #> purrr 0.3.4 2020-04-17 [1] standard (@0.3.4) #> reprex 2.0.0 2021-04-02 [1] CRAN (R 4.0.2) #> rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.2) #> rmarkdown 2.7 2021-02-19 [1] CRAN (R 4.0.2) #> sessioninfo 1.1.1 2018-11-05 [1] standard (@1.1.1) #> stringi 1.5.3 2020-09-09 [1] standard (@1.5.3) #> stringr 1.4.0 2019-02-10 [1] standard (@1.4.0) #> styler 1.4.1 2021-03-30 [1] CRAN (R 4.0.2) #> tibble 3.1.1 2021-04-18 [1] CRAN (R 4.0.3) #> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.2) #> vctrs 0.3.7 2021-03-29 [1] CRAN (R 4.0.3) #> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.3) #> xfun 0.22 2021-03-11 [1] CRAN (R 4.0.2) #> yaml 2.2.1 2020-02-01 [1] standard (@2.2.1) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
lorenzwalthert commented 3 years ago

Thanks. This is a really strange error I have come across once or twice before, In particular when I re-installed pre-commit after the initial use_precommit(), locally developed and build the upstream pre-commit and similar, but I found it not really reproducible outside pre-commit, i.e. you can do

styler::style_file(c("R/extract_replace_combine.R" ,"tests/testthat/test_extract_replace_combine.R))

and probably you won't get any error or warning. Also, reducing the number of staged files resolved the problem with pre-commit for me in other situations (although this is obviously not a viable solution).

One thing that eventually worked for me was to close my git shell / RStudio, re-installed styler and/or the pre-commit framework or package or cleared the styler cache (in that order of priority) and with some luck, it went away. If you have the latest CRAN version of styler installed (v1.4.1), trying the development version from GitHub is probably better since it has a different version number / source file and will potentially invalidate some cached initialisation misbehaviour in some low-level code (which I believe is the problem). If you don't run the latest CRAN version, updating to it is probably also fine.

It seems other people got random warnings (not errors, edit: {precommit} promoted them to errors) like that too in all kinds of places: https://community.rstudio.com/t/persistent-unknown-or-uninitialised-column-warnings/64879/20

I know this is a bit unsatisfying but I am sorry I can't offer other advise than that. Also, no one reported this before, so it does not seem to be a problem many people experience fortunately. We are also working on further isolating the hooks (switch from bare bash script to a virtual environment) as discussed in #232, so maybe this has the potential to also mitigate the problem.

lorenzwalthert commented 3 years ago

@njtierney {precommit} no longer promotes the warning Unknown or uninitialised column: text to an error. With this, I think the (random) error should go away and warnings might be occasionally encountered (but don't seem to influence the result). You can give it another try with installing the dev version of this package and put rev: c063b94 in your .pre-commit-config.yaml or wait until a new version is released and then run precommit::autopudate(). I'll bump here again if we have a new version if you prefer the latter.

njtierney commented 3 years ago

Thanks, @lorenzwalthert ! I'll get back into using this soon :)