usethis
usethis copied to clipboard
usethis cannot find path with accents.
Problem: usethis
cannot find path with accents.
The following works immediately (path has no accent):
usethis::create_package("D:/e/mypkg")
But adding an accent in the path produces an error:
usethis::create_package("D:/Γ©/mypkg")
Setting active project to 'D:/ΓΒ©/mypkg'
Error in setwd(dir = new) : cannot change working directory
We can set working directory directly and retry the command but that produces the same error. Same with:
setwd("D:/Γ©/mypkg")
usethis::create_package(getwd())
Setting active project to 'D:/ΓΒ©/mypkg'
Error in setwd(dir = new) : cannot change working directory
A workaround is to create a package using the RStudio interface. However, even after this, trying to document the package:
usethis::use_package_doc()
Error: Directory 'D:/ΓΒ©/mypkg' does not exist.
Or even checking the package with devtools:
devtools::check()
Error: Can't find 'D:/ΓΒ©/mypkg'.
Workaround is to move all files and folders in a new path without accents. However, this is not convenient and not even always possible when using shared work OneDrive paths (for instance). Resolution would be to support accented paths.
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_2.4.3 usethis_2.1.5
loaded via a namespace (and not attached):
[1] rstudioapi_0.13 magrittr_2.0.3 pkgload_1.2.4 R6_2.5.1 rlang_1.0.2 fastmap_1.1.0
[7] fansi_1.0.3 tools_4.1.2 pkgbuild_1.3.1 sessioninfo_1.2.2 utf8_1.2.2 cli_3.2.0
[13] withr_2.5.0 remotes_2.4.2 ellipsis_0.3.2 rprojroot_2.0.3 tibble_3.1.6 lifecycle_1.0.1
[19] crayon_1.5.1 brio_1.1.3 processx_3.5.3 purrr_0.3.4 callr_3.7.0 vctrs_0.4.1
[25] fs_1.5.2 ps_1.6.0 testthat_3.1.3 memoise_2.0.1 glue_1.6.2 cachem_1.0.6
[31] compiler_4.1.2 pillar_1.7.0 desc_1.4.1 prettyunits_1.1.1 pkgconfig_2.0.3
I was able to replicate this with umlauts (Γ€,ΓΌ,ΓΆ) e.g.,
usethis::create_package("D:/Code/u/mypkg")
works fine, but ΓΌ
fails:
> usethis::create_package("D:/Code/ΓΌ/mypkg")
β Creating 'D:/Code/ΓΌ/mypkg/'
β Setting active project to 'D:/Code/ΓΒΌ/mypkg'
Error in setwd(dir = new) : cannot change working directory
β Setting active project to '<no active project>'
I would urge Windows users to update to R 4.2, which has made some big strides forward in base R's handling of encoding, which is also going to bring big benefits for file paths. I haven't analyzed this particular case yet, but many problems of this nature on Windows are due to bugs/infelicities in base R itself and are almost beyond the reach of an add-on package to easily fix.
https://developer.r-project.org/Blog/public/2021/12/07/upcoming-changes-in-r-4.2-on-windows/
R 4.2.0
fixes this issue, confirmed on my end, thanks.
Good to hear!
Again, I haven't poked around usethis to see if we are doing something suboptimal, but I suspect package maintainers will increasingly advise users with path encoding problems on Windows to upgrade to R 4.2, instead of us continuing to implement special guards and workarounds.
I'm afraid I might haven spoken too fast.
In R 4.2.0, the following indeed does work:
usethis::create_package("D:/Γ©/mypkg")
usethis::use_package_doc()
devtools::document(roclets = c('rd', 'collate', 'namespace'))
But not devtools::check()
:
getwd()
"D:/Γ©/mypkg"
devtools::check()
[...]
checking R files for syntax errors ... ERROR
Error in file 'R/mypkg-package.R':
cannot open the connection
Warning in file 'R/mypkg-package.R':
cannot open file 'D:/C)/mypkg.Rcheck/00_pkg_src/mypkg/R/mypkg-package.R': No such file or directory
checking examples ... ERROR
Running massageExamples to create 'mypkg-Ex.R' failed
Error in find.package(package, lib.loc) :
there is no package called 'mypkg'
Calls: <Anonymous> -> Rd_db -> find.package
Execution halted
NONE
Seems like the accent "Γ©" is being replaced with letter "C" in the path. I've tried restarting Rstudio and my computer, to no avail.
[Edit: Removed bit about the permission denied error as it was fixed elsewhere and is only tangentially relevant to the current issue about accents: https://community.rstudio.com/t/r-4-2-0-file-rstudio-lock-creates-copying-to-build-directory-failed-permission-denied-error/136347/6. Original issue described above is still not solved.]
Since I was last here, I've discovered a problem in fs that is affecting both devtools and usethis, on Windows, for R versions prior to 4.2: https://github.com/r-lib/fs/issues/383
Once that's fixed, that should fix this.
I can't replicate your failure with R 4.2 on Windows.
# from a different R session:
# usethis::create_package(fs::path("~/Desktop/fΓΆΓΆ/fgh"))
R version 4.2.0 (2022-04-22 ucrt) -- "Vigorous Calisthenics"
<snip, snip>
> usethis::use_package_doc()
β Setting active project to 'C:/Users/jenny/Desktop/fΓΆΓΆ/fgh'
β Writing 'R/fgh-package.R'
β’ Modify 'R/fgh-package.R'
> devtools::document(roclets = c('rd', 'collate', 'namespace'))
βΉ Updating fgh documentation
βΉ Loading fgh
Writing fgh-package.Rd
> getwd()
[1] "C:/Users/jenny/Desktop/fΓΆΓΆ/fgh"
> devtools::check()
βΉ Updating fgh documentation
βΉ Loading fgh
<snip, snip>
ββ R CMD check results βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ fgh 0.0.0.9000 ββββ
Duration: 28.6s
β― checking DESCRIPTION meta-information ... WARNING
Non-standard license specification:
`use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
Standardizable: FALSE
0 errors β | 1 warning β | 0 notes β
So what you're reporting re the drive name seems like it might be a different problem. For example, I see several existing issues in fs re: a mapped network drive in Windows. Could that be relevant to your situation?
Ok, so I was going to say that for some magical reason, I just tried this again, and it worked. But I set the working directory from a different project (with no accent), then ran devtools::check()
from the console. Puzzled as to why it wasn't working before and it works now!
So I tried specifically opening the "D:\Γ©\mypkg"
RStudio project, and tried again. It failed. Which leads me to think that it might actually be an issue with RStudio.
Anyhow, I just deleted the whole folder/package and tried again. And then I was going to say that for some magical reason, the issue was gone, and it just worked.
But actually, I found out that it works with the devtools::check()
command in the console. BUT it still does the error when using the Ctr+Shift+E
shortcut, or using RStudio's Check
button. Is that weird?
In this case, do you recommend closing this issue and opening one on the RStudio community forum?
In this case, do you recommend closing this issue and opening one on the RStudio community forum?
I'd like to leave this open until the fs problem is resolved, just so people don't new issues about this known problem.
However it does seem like you might want to pursue the other RStudio and R 4.2 matter separately / elsewhere. That's not the devtools/usethis/fs problem.
For reference, I have created an RStudio community issue here and it was replicated by at least one person: https://community.rstudio.com/t/r-4-2-0-rstudio-specific-error-with-devtools-check-in-accented-path-directory/138119/2