I am distributing two questions that I asked earlier:
- Place the shape directly in the Book document (without saving its file in a folder)
- Place the shape directly in the Book document (without saving its file in a folder). Part 2
I am writing an R package that generates a .pdf file for users that outputs data summaries. I have a .Rnw script in the package (here my MWE is called test.Rnw). User can:
knit2pdf("test.Rnw", clean=T)
This simplifies the process because it automatically creates the .pdf file from the .tex file and removes unnecessary files for them (for example, .aux and .log). It also saves any images in a temporary directory (using tempdir ()), which will then be automatically cleaned by the system after they are included in the .tex and .pdf files. This means that they also do not need to erase image files.
Below is my test .Rnw MWE:
\documentclass[nohyper]{tufte-handout} \usepackage{tabularx} \usepackage{longtable} \setcaptionfont{% changes caption font characteristics \normalfont\footnotesize \color{black}% <-- set color here } \begin{document} <<setup, echo=FALSE>>= library(knitr) library(xtable) library(ggplot2)
I should note that in fact there is another .Rnw file in my package that calls the test.Rnw file via:
knit2pdf("/inst/Rnw/test.Rnw","/path/test.tex",clean=T)
In any case, I am trying to prepare this package for CRAN and ran into two problems:
1) First of all, the question of bewilderment arises: the MWE code above seems to work on Mac Systems, but doesn't seem to work on Windows! On Windows, the .pdf file that is generated does not contain images. After troubleshooting, I think I understood the problem, but still can not find a solution.
Basically, on Windows, it seems that the tempdir () command will create a double backslash path, such as \\ this \\ is \\ myPath. Then, in the .tex file, the path to the temporary directory (containing the images) is a single backslash, for example \ this \ is \ myPath. However, these must be single slashes, such as / this / is / myPath, so that the .tex file finds images stored in a temporary directory.
In fact, if I manually change the backslash to slashes in a .tex file on Windows, then I can successfully convert it to a .pdf file that successfully contains images.
I am not sure how to solve this in my syntax. I thought this would be a simple solution, but if I just do something like:
# Specify directory for figure output in a temporary directory temppath <- tempdir() gsub("\\\\", "/", temppath)
Then, images cannot be saved in the Windows temporary directory in the first place, even if the correct single slashes are specified in the .tex file. (I suppose) the same variable is used to indicate the temporary location of the directory, as well as the location of the image in the .tex file, and they must somehow have different slash directions.
I am a little surprised that this has not happened before (at least in my studies). Maybe people do not automatically erase the image when starting knitr?
2) I am wondering if it is permissible for me to add a second line in my other .Rnw file for the call:
knit2pdf("/inst/Rnw/test.Rnw","/path/test.tex",clean=T) system(sprintf("%s", paste0("rm -r ", "/path/myFile.tex")))
So the .tex file can also be automatically deleted. I am trying to confirm that such syntax will be acceptable by CRAN standards, as it involves deleting a file from a user computer (which may seem dangerous / malware), although it points specifically to the .tex file that it just generated, and therefore he should not remove anything important to them.
* Note. By default, I erase all intermediary files, so the user only deals with the .pdf file. However, I still allow users to use this option by default, and if necessary, store these intermediary files.