-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use_test() without arguments fails with RStudio project under ~ on Windows #901
Comments
Can I see full session info? And the output of usethis is stuck between a rock and a hard place given general file path misery on Windows, what rprojroot wants to do, what RStudio IDE wants to do, and what fs does (all of which are in some tension with each other). A general design principle of usethis is to align with fs in terms of our understanding of |
As a windows user, I can confirm the error. I don't recall that this happened before and I am a usethis user, so there may be a change that broke this (here or in fs). About the situation,
It is > rstudioapi::getSourceEditorContext()$path
[1] "~/testpackage/R/foo.R"
> usethis:::proj_path_prep(rstudioapi::getSourceEditorContext()$path)
C:/Users/chris/Documents/testpackage/Users/chris/testpackage/R/foo.R We can obviously see that there is something wrong in the last resulting path.
I think this should be handle in file.create(temp_file <- tempfile(tmpdir = "~"))
#> [1] TRUE
temp_file
#> [1] "~\\file8e68207943b3"
fs::path_real(temp_file)
#> C:/Users/chris/AppData/Local/Temp/Rtmp2pqIX4/reprex8058645525b2/Users/chris/file8e68207943b3
fs::path_expand(temp_file)
#> C:/Users/chris/file8e68207943b3
fs::path_expand_r(temp_file)
#> C:/Users/chris/Documents/file8e68207943b3
path.expand(temp_file)
#> [1] "C:/Users/chris/Documents\\file8e68207943b3"
normalizePath(temp_file)
#> [1] "C:\\Users\\chris\\Documents\\file8e68207943b3"
unlink(temp_file) Created on 2019-09-30 by the reprex package (v0.3.0) |
@jennybc here's the additional info in a fresh session from my side, too: usethis::use_test()
#> ✔ Setting active project to 'C:/Users/mikko/Documents/R/dev/foo'
#> Error: Open file must be in the 'R/' directory of the active package.
#> * Actual path: 'Users/mikko/R/dev/foo/R/foo.R'
usethis::proj_get()
#> C:/Users/mikko/Documents/R/dev/foo
usethis::proj_sitrep()
#> * working_directory: 'C:/Users/mikko/Documents/R/dev/foo'
#> * active_usethis_proj: 'C:/Users/mikko/Documents/R/dev/foo'
#> * active_rstudio_proj: 'C:/Users/mikko/Documents/R/dev/foo'
sessioninfo::session_info()
#> - Session info ------------------------------------------------------------
#> setting value
#> version R version 3.6.1 (2019-07-05)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RStudio
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> tz Europe/Helsinki
#> date 2019-09-30
#>
#> - Packages ----------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> backports 1.1.4 2019-04-10 [1] CRAN (R 3.6.0)
#> cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
#> clisymbols 1.2.0 2017-05-21 [1] CRAN (R 3.6.0)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
#> fs 1.3.1.9000 2019-09-28 [1] Github (r-lib/fs@380685c)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
#> purrr 0.3.2 2019-03-15 [1] CRAN (R 3.6.0)
#> Rcpp 1.0.2 2019-07-25 [1] CRAN (R 3.6.1)
#> rlang 0.4.0 2019-06-25 [1] CRAN (R 3.6.0)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
#> rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.6.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0)
#> usethis 1.5.1.9000 2019-09-28 [1] Github (r-lib/usethis@a2342b8)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
#>
#> [1] C:/Users/mikko/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library |
I tried playing around with setting the I wonder, is there any way to tell RStudio how |
I suspect this problem arose when I merged #485. If true, then, without further pre-processing of RStudio-provided paths, we seem to be choosing between having cc @jimhester |
If |
Yeah that would definitely help. And I feel like I've even discussed this with the IDE team before. But I should probably just work around this with a shim in usethis. |
@mikmart and @cderv Does the PR fix it for you? It seems to do so for me, on my Windows VM. @jimhester Could you confirm that the fix doesn't re-break things with a mapped drive on Windows? |
Yup, it's working for me now, too! 👍 |
This is the existing RStudio IDE issue I was thinking about. But this PR is a workaround implemented here. |
Thanks for the quick fix! 🙏 -- and also the link to the rstudioapi issue: that made me realize why my attempts at setting |
* Make get_active_r_file() more robust to `~/` issues on Windows Closes #901 * Simplify * Add NEWS bullet
File path checking seems to go wrong when
use_test()
tries to get the path to the active file in RStudio in a project under~
on Windows:Related r-lib/fs#221. Maybe related #485?
The text was updated successfully, but these errors were encountered: