r-lib / rprojroot

Finding files in project subdirectories
https://rprojroot.r-lib.org/
Other
149 stars 23 forks source link

`find_package_root_file()` fails on R-devel-windows when `path` is outside of pacakge folder #90

Closed Ilia-Kosenkov closed 1 year ago

Ilia-Kosenkov commented 1 year ago

Hi. While working on {rextendr} package we noticed that our tests started to fail on R-devel on Windows https://github.com/extendr/rextendr/issues/238, specifically a helper method that works on paths relative to the package root. After a couple of days of debugging, I was able to reliably reproduce this issue locally. I suspect that some features that {rprojroot} relies on work differently in the fresh version of R-devel, but I have no idea what that could be, exactly. Here is a minimal reprex:


pkg_path <- tempfile()
tryCatch(
    {
        pkg <- usethis::create_package(pkg_path)
        setwd(pkg)
        path_outside <- file.path(pkg_path, "..")
        projroot <- rprojroot::find_package_root_file(path = path_outside)
        print(projroot)
    },
    finally = unlink(pkg_path)
)
sessionInfo()

Here are test output on my local system

R-release-windows ``` r pkg_path <- tempfile() tryCatch( { pkg <- usethis::create_package(pkg_path) setwd(pkg) path_outside <- file.path(pkg_path, "..") projroot <- rprojroot::find_package_root_file(path = path_outside) print(projroot) }, finally = unlink(pkg_path) ) #> ✔ Creating 'C:/Users/.../AppData/Local/Temp/RtmpUxTXMV/file48ec7ef85667/' #> ✔ Setting active project to 'C:/Users/.../AppData/Local/Temp/RtmpUxTXMV/file48ec7ef85667' #> ✔ Creating 'R/' #> ✔ Writing 'DESCRIPTION' #> Package: file48ec7ef85667 #> Title: What the Package Does (One Line, Title Case) #> Version: 0.0.0.9000 #> Authors@R (parsed): #> * First Last [aut, cre] (YOUR-ORCID-ID) #> Description: What the package does (one paragraph). #> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a #> license #> Encoding: UTF-8 #> Roxygen: list(markdown = TRUE) #> RoxygenNote: 7.2.3 #> ✔ Writing 'NAMESPACE' #> ✔ Setting active project to '' #> Error: No root directory found in C:/Users/.../AppData/Local/Temp/RtmpUxTXMV or its parent directories. Root criterion: contains a file "DESCRIPTION" with contents matching "^Package: " sessionInfo() #> R version 4.2.2 (2022-10-31 ucrt) #> Platform: x86_64-w64-mingw32/x64 (64-bit) #> Running under: Windows 10 x64 (build 22621) #> #> Matrix products: default #> #> locale: #> [1] LC_COLLATE=English_United States.utf8 #> [2] LC_CTYPE=English_United States.utf8 #> [3] LC_MONETARY=English_United States.utf8 #> [4] LC_NUMERIC=C #> [5] LC_TIME=English_United States.utf8 #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> loaded via a namespace (and not attached): #> [1] rstudioapi_0.14 xml2_1.3.3 roxygen2_7.2.3 knitr_1.42 #> [5] magrittr_2.0.3 usethis_2.1.6 R.cache_0.16.0 R6_2.5.1 #> [9] rlang_1.0.6 fastmap_1.1.0 fansi_1.0.4 stringr_1.5.0 #> [13] styler_1.9.0 tools_4.2.2 xfun_0.37 R.oo_1.25.0 #> [17] utf8_1.2.3 cli_3.6.0 withr_2.5.0 htmltools_0.5.4 #> [21] rprojroot_2.0.3 yaml_2.3.7 digest_0.6.31 tibble_3.1.8 #> [25] lifecycle_1.0.3 crayon_1.5.2 purrr_1.0.1 vctrs_0.5.2 #> [29] R.utils_2.12.2 fs_1.5.2 glue_1.6.2 evaluate_0.20 #> [33] rmarkdown_2.20 reprex_2.0.2 stringi_1.7.12 compiler_4.2.2 #> [37] pillar_1.8.1 desc_1.4.2 R.methodsS3_1.8.2 pkgconfig_2.0.3 ``` Created on 2023-02-20 with [reprex v2.0.2](https://reprex.tidyverse.org)
R-devel-windows ``` r pkg_path <- tempfile() tryCatch( { pkg <- usethis::create_package(pkg_path) setwd(pkg) path_outside <- file.path(pkg_path, "..") projroot <- rprojroot::find_package_root_file(path = path_outside) print(projroot) }, finally = unlink(pkg_path) ) #> ✔ Creating 'C:/Users/.../AppData/Local/Temp/RtmpYD0f5E/file19b07c8de29/' #> ✔ Setting active project to 'C:/Users/.../AppData/Local/Temp/RtmpYD0f5E/file19b07c8de29' #> ✔ Creating 'R/' #> ✔ Writing 'DESCRIPTION' #> Package: file19b07c8de29 #> Title: What the Package Does (One Line, Title Case) #> Version: 0.0.0.9000 #> Authors@R (parsed): #> * First Last [aut, cre] (YOUR-ORCID-ID) #> Description: What the package does (one paragraph). #> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a #> license #> Encoding: UTF-8 #> Roxygen: list(markdown = TRUE) #> RoxygenNote: 7.2.3 #> ✔ Writing 'NAMESPACE' #> ✔ Setting active project to '' #> [1] "." sessionInfo() #> R Under development (unstable) (2023-02-19 r83869 ucrt) #> Platform: x86_64-w64-mingw32/x64 (64-bit) #> Running under: Windows 11 x64 (build 22621) #> #> Matrix products: default #> #> #> locale: #> [1] LC_COLLATE=English_United States.utf8 #> [2] LC_CTYPE=English_United States.utf8 #> [3] LC_MONETARY=English_United States.utf8 #> [4] LC_NUMERIC=C #> [5] LC_TIME=English_United States.utf8 #> #> time zone: Europe/Helsinki #> tzcode source: internal #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> loaded via a namespace (and not attached): #> [1] crayon_1.5.2 vctrs_0.5.2 cli_3.6.0 knitr_1.42 #> [5] rlang_1.0.6 xfun_0.37 stringi_1.7.12 purrr_1.0.1 #> [9] styler_1.9.0 glue_1.6.2 rprojroot_2.0.3 htmltools_0.5.4 #> [13] roxygen2_7.2.3 fansi_1.0.4 rmarkdown_2.20 R.cache_0.16.0 #> [17] evaluate_0.20 tibble_3.1.8 fastmap_1.1.0 yaml_2.3.7 #> [21] lifecycle_1.0.3 stringr_1.5.0 compiler_4.3.0 fs_1.5.2 #> [25] pkgconfig_2.0.3 rstudioapi_0.14 R.oo_1.25.0 R.utils_2.12.2 #> [29] digest_0.6.31 R6_2.5.1 reprex_2.0.2 utf8_1.2.3 #> [33] usethis_2.1.6 pillar_1.8.1 magrittr_2.0.3 R.methodsS3_1.8.2 #> [37] tools_4.3.0 withr_2.5.0 desc_1.4.2 xml2_1.3.3 ``` Created on 2023-02-20 with [reprex v2.0.2](https://reprex.tidyverse.org)

If this is not an issue in {rprojroot} but rather in R itself, it would be nice if we could pinpoint it and report it to the devs.

yutannihilation commented 1 year ago

I think this is the route cause.

❯ & 'C:\Program Files\R\R-devel\bin\Rscript.exe' -e "dirname('C:/')"
[1] "."

~
❯ & 'C:\Program Files\R\R-4.2.2\bin\Rscript.exe' -e "dirname('C:/')"
[1] "C:/"

~

Because of this, is_root() fails to recognize C:/ is the root.

https://github.com/r-lib/rprojroot/blob/49a1a644246abcdcbe11a9396b1bb147d0919853/R/root.R#L130-L136

yutannihilation commented 1 year ago

Asked on R-devel.

https://stat.ethz.ch/pipermail/r-devel/2023-February/082370.html

yutannihilation commented 1 year ago

Should be fixed now.

https://github.com/wch/r-source/commit/d444c07b7fe765ce65224faa2e85f0819a189e1a

krlmlr commented 1 year ago

Thanks for your help on this! Closing, let's open a new issue if similar problems arise in the future.