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

Allow dots in file names in .rnw files #2213

Closed
otoomet opened this issue Jan 27, 2023 · 4 comments
Closed

Allow dots in file names in .rnw files #2213

otoomet opened this issue Jan 27, 2023 · 4 comments

Comments

@otoomet
Copy link

otoomet commented Jan 27, 2023

I prefer to use automatically generated figures in .figs folder to make the folder invisible and stress it is autogenerated (I also use .cache for the caches). However, knitr changes the leading dot to an underscire when working for .rnw (latex) files (see also #1471). This post here is both bug report and feature request:

A minimal example (file "test.rnw"):

\documentclass{article}
\usepackage{graphicx}
<<>>=
knitr::opts_chunk$set(fig.path=".figs/")
@ 
\begin{document}
<<>>=
plot(10:1)
@
\end{document}

and this can be compiled with:

Rscript -e "knitr::knit('test.rnw')"

Knitr (correctly) gives a message about replacing dots with underscores.

Session info:

$ Rscript -e "xfun::session_info('knitr')"
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.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:
  evaluate_0.16   graphics_4.2.2  grDevices_4.2.2 highr_0.9      
  knitr_1.42      methods_4.2.2   stats_4.2.2     tools_4.2.2    
  utils_4.2.2     xfun_0.36       yaml_2.3.5   

The bug part

This feature (changing dots to underscores) is not documented. Neither ?knitr::opts_chunk nor the website it refers to currently mention sanitization, the website currently states that:

fig.path: ('figure/'; character) A prefix to be used to generate figure file paths. fig.path and chunk labels are concatenated to generate the full paths. It may contain a directory like figure/prefix-; the directory will be created if it does not exist.

As a note, dots are allowed in .rmd/markdown related paths, this creates confusion as why it sometimes works and sometimes does not work.

Hence my request to document the behavior.

The feature request part.

It seems that modern latex supports dots in file names. For instance, a file

\documentclass{article}
\usepackage{graphicx}
<<>>=
knitr::opts_chunk$set(fig.path=".figs/")
@ 
\begin{document}
<<>>=
plot(10:1)
@
% note: not a self-contained example, you need the the 'picture.pdf' below
% note: path contains a leading dot!
\includegraphics{.figs/picture.pdf}
\end{document}

compiles correctly using ubuntu 20.04
(pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) and XeTeX 3.14159265-2.6-0.999991 (TeX Live 2019/Debian))

Alternatively, if allowing dots globally is considered not a good idea, then can you make it optional using some sort of sanitize=TRUE/FALSE option?

Thank you for considering :-)


By filing an issue to this repo, I promise that

  • [x ] I have fully read the issue guide at https://yihui.org/issue/.
  • [ x] 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('knitr'). 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('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [ x] 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.

@yihui
Copy link
Owner

yihui commented Feb 2, 2023

Thanks for the detailed report! Would it meet your demand if I allow leading dots? Then .figs/ will be respected, but .figs/foo.bar will still be changed to .figs/foo_bar.

can you make it optional using some sort of sanitize=TRUE/FALSE option?

That sounds like a good idea. Yes, I think I can do it.

@yihui yihui moved this to To discuss / To plan in R Markdown Team Projects Feb 2, 2023
@otoomet
Copy link
Author

otoomet commented Feb 13, 2023

Thanks! Leading dot is all I need (at least in the foreseeable future :-) )

If I were the designing the package--I'd probably leave the dots alone, and just tell the user that they have to figure out what file names are legal given the software/OS they use.

But anyway, appreciate your work in what seems like a quite big project!

@yihui yihui moved this from To discuss / To plan to Todo In Progress in R Markdown Team Projects Feb 13, 2023
@yihui yihui closed this as completed in a007b37 Feb 13, 2023
@github-project-automation github-project-automation bot moved this from Todo In Progress to Done in R Markdown Team Projects Feb 13, 2023
@yihui
Copy link
Owner

yihui commented Feb 13, 2023

Done. Dots are left untouched now.

To prevent other special characters from being sanitized, you can set options(knitr.sanitize.paths = FALSE).

Thanks!

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants