DanChaltiel / autoimport

A toolbox to automatically generate @importFrom roxygen tags from R files.
https://danchaltiel.github.io/autoimport/
13 stars 2 forks source link

Cannot rename file #25

Closed mihem closed 2 weeks ago

mihem commented 2 weeks ago

@DanChaltiel thanks for this package. I found this super useful and great user experience (e.g. with shiny diff). However, I'll encounter an issue when renaming the file

Describe the bug ater running autoimport::autoimport the first message look allright to me


── Init ───────────────────────────────────────────────────────────────────────────────────────────────────────────
Autoimporting for package scMisc at .
✔ Registered namespaces of 29 dependencies.

── Reading ────────────────────────────────────────────────────────────────────────────────────────────────────────
ℹ Found 1 function in file ./R/annotation.R (133 lines)
ℹ Found 3 functions in file ./R/general_helper.R (59 lines)
ℹ Found 6 functions in file ./R/seurat_helper.R (341 lines)
ℹ Found 1 function in file ./R/utils-pipe.R (14 lines)
ℹ Found 15 functions in file ./R/visualization.R (899 lines)
✔ Found a total of 26 internal functions in 5 files (1446 lines).

── Parsing ────────────────────────────────────────────────────────────────────────────────────────────────────────
→ File annotation.R
! Reading from cache
ℹ Found 19 functions to import in 1 function or code chunk.
→ File general_helper.R
! Reading from cache
ℹ Found 17 functions to import in 3 functions or code chunks.
→ File seurat_helper.R
! Reading from cache
ℹ Found 52 functions to import in 6 functions or code chunks.
→ File utils-pipe.R
! Reading from cache
ℹ Found 0 functions to import in 1 function or code chunk.
→ File visualization.R
! Reading from cache
ℹ Found 274 functions to import in 15 functions or code chunks.
✔ Found a total of 362 potential functions to import

I have to make a few choices and so, everything seems to works fine, but then at the end:

→ Accepting modification of 'R//annotation.R'
Warning in file.rename(new_path[[i()]], old_path[[i()]]) :
  cannot rename file '/tmp/RtmpuExX9y/autoimport_temp_target_dir/annotation.R' to 'R//annotation.R', reason 'Invalid cross-device link'
→ Accepting modification of 'R//general_helper.R'
Warning in file.rename(new_path[[i()]], old_path[[i()]]) :
  cannot rename file '/tmp/RtmpuExX9y/autoimport_temp_target_dir/general_helper.R' to 'R//general_helper.R', reason 'Invalid cross-device link'
→ Accepting modification of 'R//seurat_helper.R'
Warning in file.rename(new_path[[i()]], old_path[[i()]]) :
  cannot rename file '/tmp/RtmpuExX9y/autoimport_temp_target_dir/seurat_helper.R' to 'R//seurat_helper.R', reason 'Invalid cross-device link'
→ Accepting modification of 'R//visualization.R'
Warning in file.rename(new_path[[i()]], old_path[[i()]]) :
  cannot rename file '/tmp/RtmpuExX9y/autoimport_temp_target_dir/visualization.R' to 'R//visualization.R', reason 'Invalid cross-device link'
✔ Review complete

So there is a problem with renaming, maybe because there are suddently two forward slashes?

Session info

``` sessionInfo() R version 4.4.2 (2024-10-31) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 24.04.1 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=de_DE.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C time zone: Europe/Berlin tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] shiny_1.9.1 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 [5] dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 [9] tibble_3.2.1 ggplot2_3.5.1 tidyverse_2.0.0 scMisc_0.4.0 [13] Seurat_5.1.0 SeuratObject_5.0.2 sp_2.1-4 testthat_3.2.1.1 ```
DanChaltiel commented 2 weeks ago

Thanks for reporting the issue! This seems to be a Linux problem that I didn't see coming.

TODO:

DanChaltiel commented 2 weeks ago

Hi @mihem

I added Linux to the test suite and there were no problems during checks: https://github.com/DanChaltiel/autoimport/actions/runs/11833281274 This means I unfortunately cannot reproduce this issue.

I switched from base R to fs for all that pertains to paths, I think this should prevent all double / problems. Could you rerun the function and tell me if it fixed it? Thanks!

mihem commented 2 weeks ago

Hi @DanChaltiel Thanks for the fast reply. Yeah, I think Linux checks are obligatory for CRAN submission.

I updated autocomplete (also removed the cache to be on the safe side), but the error was the same

Warning in file.rename(new_path[[i()]], old_path[[i()]]) :
  cannot rename file '/tmp/RtmpDGriP5/autoimport_temp_target_dir/visualization.R' to 'R//visualization.R', reason 'Invalid cross-device link'

To make this reproducible I created a dummy example: https://github.com/mihem/testAutoimport

I actually found two further bugs then https://github.com/DanChaltiel/autoimport/issues/27 https://github.com/DanChaltiel/autoimport/issues/28

Also when running autoimport I get:

→ Accepting modification of './R/fun.R'
Warning in file.rename(new_path[[i()]], old_path[[i()]]) :
  cannot rename file '/tmp/RtmpRzzNfW/autoimport_temp_target_dir/fun.R' to './R/fun.R', reason 'Invalid cross-device link'

So the problem with the 2 // is not a problem here (don't now why i still have that problem in my real project then). But the problem with renaming remains.

I tried to debug it a little:

tmp <- tempfile(fileext = ".R")
writeLines("Temporary content", tmp) 
file.rename(tmp, "./R/fun.R")

fails with the same error

Warning message:
In file.rename(tmp, "./R/fun.R") :
  cannot rename file '/tmp/RtmpRzzNfW/file3df64f7683501c.R' to './R/fun.R', reason 'Invalid cross-device link'

While file.copy or fs::file_move work fine:

file.copy(tmp, "./R/fun.R", overwrite = TRUE)
fs::file_move(tmp, "./R/fun.R")