r-lib / devtools

Tools to make an R developer's life easier
https://devtools.r-lib.org
Other
2.37k stars 753 forks source link

check if `.R` directory exists before calling `lint()` with `cache = TRUE` #2408

Closed ax-sc closed 2 years ago

ax-sc commented 2 years ago

Thank you for providing this package and the tools beneath. When using devtools::lint() to lint the source code of a local package without changing any defaults I got the following error:

.Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning messages:
1: In dir.create(path) :
  cannot create dir '/Users/axel/.R/lintr_cache', reason 'No such file or directory'
2: In gzfile(file, "wb") :
  cannot open compressed file '/Users/axel/.R/lintr_cache/638da06b9726522683c05aa11150f6363bbfce89', probable reason 'No such file or directory'

This was confusing to me first as lintr::lint_package() succeeds (without changing any defaults). After checking my user directory and seeing that there is no .R directory i figured out that the difference between devtools::lint() and lintr::lint() is the default value of cache, which is TRUE in devtools and FALSE in lintr.

Therefore it might be a good idea (if the difference in defaults is intended) to check the existence of the .R directory before trying to use it for the cache and provide the user with a more meaningful cli-warning or even create it if it does not exist (creating the directory manually did solve the problem).

Let me know if I should provide any additional info or create a pull request to fix this (for which your advise on the intended behaviour would be needed).

Here is the output of sessionInfo():

R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin20.6.0 (64-bit)
Running under: macOS Monterey 12.2

Matrix products: default
LAPACK: /opt/homebrew/Cellar/r/4.1.2/lib/R/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] spelling_2.2       xfun_0.29          remotes_2.4.2      purrr_0.3.4        pak_0.2.1          vctrs_0.3.8       
 [7] testthat_3.1.2     usethis_2.1.5      htmltools_0.5.2    yaml_2.2.2         utf8_1.2.2         rlang_0.4.12      
[13] pkgbuild_1.3.0     pillar_1.6.4       glue_1.6.0         withr_2.4.3        hunspell_3.0.1     sessioninfo_1.2.2 
[19] lifecycle_1.0.1    stringr_1.4.0      lintr_2.0.1        commonmark_1.7     devtools_2.4.3     codetools_0.2-18  
[25] memoise_2.0.1      evaluate_0.14      knitr_1.37         callr_3.7.0        fastmap_1.1.0      ps_1.6.0          
[31] rex_1.2.1          fansi_0.5.0        Rcpp_1.0.7         cachem_1.0.6       desc_1.4.0         pkgload_1.2.4     
[37] fs_1.5.2           xmlparsedata_1.0.5 brio_1.1.3         digest_0.6.29      stringi_1.7.6      processx_3.5.2    
[43] rprojroot_2.0.2    cli_3.1.1          tools_4.1.2        magrittr_2.0.1     lazyeval_0.2.2     tibble_3.1.6      
[49] crayon_1.4.2       pkgconfig_2.0.3    ellipsis_0.3.2     xml2_1.3.3         prettyunits_1.1.1  cyclocomp_1.1.0   
[55] rmarkdown_2.11     httr_1.4.2         rstudioapi_0.13    R6_2.5.1           compiler_4.1.2
jennybc commented 2 years ago

I can't reproduce this. In any case, it also would seem to be a lintr problem. And it looks like it's fixed in dev lintr.

https://github.com/r-lib/lintr/blame/d52a650d733e3a733432530c6cdef8db7533edd7/NEWS.md#L7-L8