r-lib / usethis

Set up commonly used 📦 components
https://usethis.r-lib.org/
Other
866 stars 286 forks source link

usethis::create_package() fails in temporary directory #2069

Open kevinushey opened 1 month ago

kevinushey commented 1 month ago
> usethis::create_package("/tmp/project")
Error in `check_path_is_directory()`:
✖ private/tmp is not a directory.
Run `rlang::last_trace()` to see where the error occurred.
> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.0

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

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

time zone: America/Los_Angeles
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] compiler_4.4.1  magrittr_2.0.3  cli_3.6.3       tools_4.4.1
 [5] pillar_1.9.0    fs_1.6.4        glue_1.8.0      tibble_3.2.1
 [9] utf8_1.2.4      fansi_1.0.6     vctrs_0.6.5     usethis_3.0.0
[13] lifecycle_1.0.4 pkgconfig_2.0.3 rlang_1.1.4     purrr_1.0.2

The problem here occurs because /tmp is a symlink to private/tmp, but it doesn't get resolved correctly. Here:

https://github.com/r-lib/usethis/blob/b4e84773d1e5e12c60fa2bfc85b19819393fc517/R/directory.R#L42-L44

But:

Browse[1]> fs::link_path("/tmp")
private/tmp

Note that the link path is relative, not absolute, and so needs to be interpreted relative to the directory holding the symlink.

kevin@MBP-P2MQ:/
$ ll | grep tmp
lrwxr-xr-x@  1 root  wheel    11B Sep  5 13:54 tmp@ -> private/tmp
kevinushey commented 1 month ago

The simplest solution here is probably just to use normalizePath() or the fs equivalent here?