Closed netique closed 3 years ago
Hi, this is an issue due to how Windows represents directories paths.
While Operating Systems based on Unix (such as Linux and Max OS) uses the slash (/
) to separate the parts of a path, Windows uses the backslash (\
).
So, the file you want to open, in a Unix based OS is represented as docs/_main.pdf
, while in Windows it is represented as docs\_main.pdf
.
Given that in R \
is used as an escape character (for representing special characters like \n
or \t
), you have to write your path as docs\\_main.pdf
. This way, \\
is used to represent the single backslash in the path.
I fixed this issue modifying the Makefile
replacing Rscript -e 'browseURL("docs/_main.pdf")'
at line 4 with Rscript -e 'browseURL(ifelse(.Platform[["OS.type"]] == "windows", "docs\\_main.pdf", "docs/_main.pdf"))'
On R, .Platform[["OS.type"]]
will return "windows"
if R is running on Windows and "unix"
if R is running on Linux or Mac OS.
This is the whole Makefile
with the fix on pdf, gitbook and word:
pdf:
Rscript -e 'options(bookdown.render.file_scope = FALSE); bookdown::render_book("index.Rmd", output_format = "bookdown::pdf_book")'
rm -f *.log *.mtc* *.maf *.aux *.bcf *.lof *.lot *.out *.toc front-and-back-matter/abbreviations.aux
Rscript -e 'browseURL(ifelse(.Platform[["OS.type"]] == "windows", "docs\\_main.pdf", "docs/_main.pdf"))'
gitbook:
Rscript -e 'options(bookdown.render.file_scope = FALSE); bookdown::render_book("index.Rmd", output_format = "bookdown::gitbook")'
Rscript -e 'browseURL(ifelse(.Platform[["OS.type"]] == "windows", "docs\\index.html", "docs/index.html"))'
word:
Rscript -e 'options(bookdown.render.file_scope = FALSE); bookdown::render_book("index.Rmd", output_format = "bookdown::word_document2")'
Rscript -e 'browseURL(ifelse(.Platform[["OS.type"]] == "windows", "docs\\_main.docx", "docs/_main.docx"))'
clean:
rm -f *.log *.mtc* *.maf *.aux *.bbl *.blg *.xml
clean-knits:
rm -f *.docx *.html *.pdf *.log *.maf *.mtc* *.tex *.toc *.out *.lof *.lot *.bcf *.aux
rm -R *_files
rm -R *_cache
Thanks for flagging this issue!
I've just pushed a fix - the Makefile now uses the here
package to build the filepath, which should ensure cross-platform compatibility (I tested it on Mac OS and Windows 10).
Can you try downloading the latest version from GitHub and checking it it works?
When clicking on "Build All" button in RStudio, the PDF renders just fine, but will not open. I have found out that this is actually a problem with
browseURL()
command. When replaced withsystem2("open", "docs/_main.pdf")
, everything compiles and opens according the expectations.EDIT: There is sort of important argument, which should be used for our purpose and the line should then be like:
Rscript -e 'system2("open", "docs/_main.pdf", wait = FALSE)'
. Otherwise, RStudio Build pane waits for something I do not really understand and the red STOP button is active. Withwait = FALSE
, this behaviour is corrected.Here is the error message:
And sessionInfo: