Skip to content
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

file.rename() issue when rendering to another device #804

Closed
3 tasks done
Giqles opened this issue Nov 5, 2019 · 9 comments · Fixed by #1476
Closed
3 tasks done

file.rename() issue when rendering to another device #804

Giqles opened this issue Nov 5, 2019 · 9 comments · Fixed by #1476
Assignees
Labels
bug an unexpected problem or unintended behavior

Comments

@Giqles
Copy link

Giqles commented Nov 5, 2019

I think as reported under rmarkdown#705 and rmarkdown#1288, the use of file.rename() to move outputs to output_dir can cause problems. There is a suggested method to fix in those issues; using a fallback to file.copy() as in your tinytex package

Output created: /data/output/docs/book/index.html
Error in abs_path(output_file) : 
  The file '/data/output/docs/book/index.html' does not exist.
In addition: Warning messages:
1: In file.rename(files[i], files2[i]) :
  cannot rename file 'index.html' to '/data/output/docs/book/index.html', reason 'Invalid cross-device link'
> xfun::session_info("bookdown")
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.7 (Maipo), RStudio 1.1.442

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
  LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
  LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  backports_1.1.2 base64enc_0.1.3 bookdown_0.13   digest_0.6.18   evaluate_0.14   glue_1.3.1     
  graphics_3.6.0  grDevices_3.6.0 highr_0.7       htmltools_0.3.6 jsonlite_1.6    knitr_1.25     
  magrittr_1.5    markdown_0.8    methods_3.6.0   mime_0.5        Rcpp_1.0.2      rmarkdown_1.16 
  rprojroot_1.3.2 stats_3.6.0     stringi_1.2.4   stringr_1.4.0   tinytex_0.16    tools_3.6.0    
  utils_3.6.0     xfun_0.9        yaml_2.2.0

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('bookdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/bookdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@cderv cderv added the bug an unexpected problem or unintended behavior label Mar 29, 2021
@katrinabrock
Copy link

katrinabrock commented Sep 30, 2024

I'm hitting this issue as well. It seems here:

file.rename(files[i], files2[i])

and here:

on.exit(file.rename(unlist(meta)[move], files_md[move]), add = TRUE)

I am trying to run the build in docker with the source and the build target as separately mounted volumes. I'll post a full MRE when I have a bit more time on my hands.

Session Info
> xfun::session_info("bookdown")
R version 4.4.1 (2024-06-14)
Platform: aarch64-unknown-linux-gnu
Running under: Ubuntu 22.04.5 LTS

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
  LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3   bookdown_0.40.1   bslib_0.8.0       cachem_1.1.0     
  cli_3.6.3         digest_0.6.37     evaluate_1.0.0    fastmap_1.2.0    
  fontawesome_0.5.2 fs_1.6.4          glue_1.7.0        graphics_4.4.1   
  grDevices_4.4.1   highr_0.11        htmltools_0.5.8.1 jquerylib_0.1.4  
  jsonlite_1.8.9    knitr_1.48        lifecycle_1.0.4   memoise_2.0.1    
  methods_4.4.1     mime_0.12         R6_2.5.1          rappdirs_0.3.3   
  rlang_1.1.4       rmarkdown_2.28    sass_0.4.9        stats_4.4.1      
  tinytex_0.53      tools_4.4.1       utils_4.4.1       xfun_0.47        
  yaml_2.3.10 

@cderv
Copy link
Collaborator

cderv commented Oct 1, 2024

@yihui should we have a tinytex:::file_rename as xfun::file_rename() maybe to use across all packages if this is still an issue ?

@yihui
Copy link
Member

yihui commented Oct 1, 2024

Yes, I can do that, but tinytex:::file_rename() doesn't appear to be vectorized and I also need to think more about the case of renaming directories. I'll export xfun::file_rename() after solving these two problems, and then use it in bookdown.

yihui added a commit to yihui/xfun that referenced this issue Oct 2, 2024
yihui added a commit that referenced this issue Oct 2, 2024
… rename files across different disk volumes
@yihui yihui linked a pull request Oct 2, 2024 that will close this issue
@yihui yihui closed this as completed in 2770a24 Oct 2, 2024
@yihui
Copy link
Member

yihui commented Oct 2, 2024

Should be fixed now. You can install the development versions via

install.packages('xfun', repos = 'https://yihui.r-universe.dev')
install.packages('bookdown', repos = 'https://rstudio.r-universe.dev', type = 'source')

I can make new CRAN releases after you confirm that the fix works for you. Thanks!

@hadley
Copy link
Member

hadley commented Oct 6, 2024

This appears to have broken my daily builds of the mastering shiny book: https://github.com/hadley/mastering-shiny/actions/runs/11196949315/job/31126358848.

Hmmmm, probably because bookdown doesn't require xfun 0.48, so the GHA install is falling back to an install from the most recent binary. So maybe this will resolve itself in a few days.

@yihui
Copy link
Member

yihui commented Oct 7, 2024

Bumped xfun version and this should be fixed now. Thanks!

@katrinabrock
Copy link

Thank you!!

@katrinabrock
Copy link

@yihui Installing the dev version way you suggest results in:

build-site-1  | Error in file_rename(out, out_expected) : 
build-site-1  |   could not find function "file_rename"
build-site-1  | Calls: local -> eval.parent -> eval -> eval -> eval -> eval
build-site-1  | Execution halted
build-site-1  | Error in Rscript_render(f, render_args, render_meta, add1, add2) : 
build-site-1  |   Failed to compile index.Rmd
build-site-1  | Calls: <Anonymous> -> render_new_session -> Rscript_render
build-site-1  | Execution halted

However, with remotes::install_github('rstudio/bookdown'), everything is working and the bug is fixed.

@yihui
Copy link
Member

yihui commented Oct 7, 2024

@katrinabrock Oh, that was because r-universe failed to build bookdown last night (since xfun 0.48 was just released to CRAN a couple of days ago). If installing from Github works, I think the bug was indeed fixed. Thanks for the confirmation!

clrpackages pushed a commit to clearlinux-pkgs/R-xfun that referenced this issue Oct 15, 2024
Arnaud Gallou (1):
      Remove `installed.packages()` usage and call `tools::standard_package_names()` instead (#91)

Yihui Xie (27):
      start the next version
      add .r and .rmd to the mimemap
      let [] return NULL instead of list()
      take advantage of the `bytes` argument of tools::md5sum() if available: wch/r-source@c91b845
      add a function mime_type(), which doesn't have to depend on the mime package, because MIME types could be obtained from system commands
      need to add System.Web before using the class
      it's also possible to call the `file` command on Windows (if Cygwin or Rtools is installed)
      if the mime type returned from command line doesn't appear to be valid, don't cache it but issue a warning instead
      use tools:::mime_type() if possible, and leave command-line as the last resort
      fix yihui/litedown#29: call browseURL() to open the app (getOptions('browser') is not a function in a normal R session outside RStudio)
      fix yihui/litedown#30: keep guess_type() until the next release of litedown
      follow the suggestion at yihui/litedown#30 (comment) to print the URL of the app (unless open = FALSE)
      partially revert 5557263bfd064efcfe7f241f094f8e5b73e427c8: base64_uri() no longer requires the mime package
      the mime package is no longer required
      add a method record_print.record_asis(), which is an identity function
      rename .ps1 to .txt to bypass the security scan on certain platforms (sigh...)
      add tests for .mime_cmd()
      make sure the powershell script is tested on windows
      not sure who is dumber
      revert fa1e0f15dec0f63bd648cf5afb50132691e2fe70: the URL is an implementation detail, and based on private API, so probably should be hidden from users by default; if they really want to see the URL, they should explicitly print it
      add new functions html_tag(), html_value(), html_escape(), and html_view() and remove dependency on htmltools
      add a function file_rename() for rstudio/bookdown#804
      add tests for file_rename()
      remove dependency on {markdown}, and switch to litedown
      url redirect
      just get rid of this URL since I trip on it every time I submit to CRAN
      CRAN release v0.48
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Oct 26, 2024
# CHANGES IN xfun VERSION 0.48

- Added utilities for HTML tags: `html_tag()`, `html_escape()`,
  `html_escape()`, and `html_view()`. Removed the soft dependency on
  the **htmltools** package accordingly.

- `base_pkgs()` is faster now: it calls
  `tools::standard_package_names()` if the function exists (R >=
  4.4.0), otherwise it just returns a constant vector of base package
  names (thanks, @arnaudgallou, #91).

- Added a function `mime_type()` to obtain the MIME types of files via
  `mime::guess_type()` if **mime** is installed, otherwise it will
  call `tools:::mime_type()`, and fall back to using a system command
  (e.g., `file --mime-type`) to obtain the types.

- Added a function `file_rename()` to deal with `file.rename()`
  failures by calling `file.copy()` (thanks, @Giqles @katrinabrock,
  rstudio/bookdown#804).

- `new_app()` will use `utils::browseURL()` to open the app if
  `options('viewer')` is not configured (thanks, @AlbertLei,
  yihui/litedown#29).

- Added a method `record_print.record_asis()` to return the object as is.

# CHANGES IN xfun VERSION 0.47

- Added functions `lazy_save()` and `lazy_load()` to save objects to
  files and lazy-load them.

- Fixed a bug in `record(dev = svglite::svglite)` that misplaced plots
  when low-level plot functions are used (thanks, @liao961120,
  yihui/litedown#17).

- Specified the lowest R version required (v3.2.0) for this package.

# CHANGES IN xfun VERSION 0.46

- `md_table()` should add a vertical ellipsis to row names when rows
  are truncated by the `limit` argument.

- `session_info()` recognizes Positron now (thanks, @chuxinyuan, #89).

# CHANGES IN xfun VERSION 0.45

- For `record()` with `verbose = 1` or `2`, invisible `NULL` is no
  longer printed.

- `Rscript_call()` will show the actual error message (if an error
  occurred) during calling the function in a new R session.

# CHANGES IN xfun VERSION 0.44

- Added a function `cache_exec()` to cache the execution of an
  expression either in memory or on disk. It is much more general and
  flexible than `cache_rds()`. For example, it supports custom
  reading/writing methods for cache files, and can load locally
  created variables in the expression while loading cache.

- Added an argument `cache` to `record()` to make it possible to enable caching.

- Added arguments `message` and `warning` to `record()` to decide
  whether messages and warnings should be recorded.

- Changed the default value of the argument `error` of `record()` from
  `FALSE` to `NA`. Now `FALSE` means to suppress error messages, and
  `NA` means to throw errors normally. This is for consistency with
  the `message` and `warning` arguments.

- Added an S3 generic function `record_print()`, which is similar to
  `knitr::knit_print()` but for the purpose of printing visible values
  in `record()`.

- The `record()` function gained new arguments `print` and
  `print.args` to support custom printing functions and arguments.

- Added a function `md_table()`, which is a minimal Markdown table
  generator.

- Exported the internal function `md5()` to calculate the MD5
  checksums of R objects. The function is essentially a workaround for
  `tools::md5sum()` (see HenrikBengtsson/Wishlist-for-R#21).

- For `fenced_block()`, a space is added between the backticks and the
  language name, e.g., ```` ```r ```` has become ```` ``` r ````
  now. This will affect snapshot tests based on Markdown ([an
  example](yihui/knitr-examples@931e0a2)).

- Added a shorthand `fenced_div()` for `fenced_block(char = ':')`.

- `write_utf8()` returns the `con` argument (typically a file path)
  now. Previously, it returns `NULL`.

- Added an experimental function `new_app()` to create a local web application.

- The returned value of `yaml_body()` contains a new element `lines`
  in the list indicating the line numbers of YAML metadata if exists.

- Removed the `skip` argument from `split_source()`.

- For `split_source(line_number = TRUE)`, the attribute name for line
  numbers in the returned value was changed from `line_start` (a
  single starting line number) to `lines` (both the starting and
  ending numbers).

- Fixed an edge case in `prose_index()`, in which inline code was
  incorrectly recognized as a code block fence.

# CHANGES IN xfun VERSION 0.43

- Added a function `upload_imgur()`, which was adapted from
  `knitr::imgur_upload()`. The latter will call the former in the
  future. `xfun::upload_imgur()` allows users to choose whether to use
  the system command `curl` or the R package **curl** to upload the
  image. It also has a new argument `include_xml` to specify whether
  the XML response needs to be included in the returned value.

- Added a function `fenced_block()` to create a fenced block in
  Markdown (thanks, @cderv, yihui/knitr#2331). The block can be either
  a code block or a fenced Div.

- Fixed a bug in `xfun::record()` when the argument `verbose = 1` or `2`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants