Windows system call fails while building the book "R Packages" - r

I'm trying to build Hadley's book "R Packages" from source. I have downloaded and unzipped the source and am have combined the code from Getting started (with some modifications) and the code in r-pkgs-first-edition-freeze\book\build-book.r to build the book (original code at the of this post). The first part of the code from Getting started works as expected:
# install.packages(c("devtools", "roxygen2", "testthat", "knitr")) # orginal code
library(devtools); library(roxygen2); library(testthat); library(knitr) # what I'm using
# install.packages("rstudioapi") # orginal code
library(rstudioapi) # what I'm using
rstudioapi::isAvailable("0.99.149")
[1] TRUE # expected result
In the next part, has_devel() doesn't give the verbose output described in Getting started, but it also doesn't throw an error, and .Last.value == TRUE, as expected, so I think I'm OK:
devtools::install_github("r-lib/devtools")
has_devel()
.Last.value
[1] TRUE
The last part of the code from Getting started also works. Many of my packages are newer versions compared to what is listed in Getting started, but I don't think this is the source of my subsequent problems.
library(roxygen2)
library(testthat)
devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────
setting value
version R version 3.5.1 (2018-07-02)
os Windows 7 x64 SP 1
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.1252
tz America/Chicago
date 2019-04-10
─ Packages ───────────────────────────────────────────────────────────────
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.5.1)
backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
callr 2.0.4 2018-05-15 CRAN (R 3.5.1)
cli 1.0.0 2017-11-05 CRAN (R 3.5.1)
clisymbols 1.2.0 2017-05-21 CRAN (R 3.5.1)
commonmark 1.5 2018-04-28 CRAN (R 3.5.1)
crayon 1.3.4 2017-09-16 CRAN (R 3.5.1)
desc 1.2.0 2018-05-01 CRAN (R 3.5.1)
devtools * 2.0.2.9000 2019-04-11 Github (r-lib/devtools#ab6c878)
digest 0.6.15 2018-01-28 CRAN (R 3.5.1)
evaluate 0.11 2018-07-17 CRAN (R 3.5.1)
fs 1.2.5 2018-07-30 CRAN (R 3.5.1)
glue 1.3.0 2018-07-17 CRAN (R 3.5.1)
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1)
knitr * 1.20 2018-02-20 CRAN (R 3.5.1)
magrittr 1.5 2014-11-22 CRAN (R 3.5.1)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.1)
oldbookdown * 0.1 2019-04-11 Github (hadley/oldbookdown#0ffc6fb)
pkgbuild 1.0.3 2019-04-11 Github (r-lib/pkgbuild#79cb7a0)
pkgload 1.0.1.9000 2019-04-11 Github (r-lib/pkgload#0ef4f58)
prettyunits 1.0.2 2015-07-13 CRAN (R 3.5.1)
processx 3.1.0 2018-05-15 CRAN (R 3.5.1)
R6 2.2.2 2017-06-17 CRAN (R 3.5.0)
Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.1)
remotes 2.0.3 2019-04-09 url
RevoUtils * 11.0.1 2018-08-01 local
RevoUtilsMath * 11.0.0 2018-08-01 local
rlang 0.2.1 2018-05-30 CRAN (R 3.5.1)
rmarkdown * 1.10 2018-06-11 CRAN (R 3.5.1)
roxygen2 * 6.1.0 2018-07-27 CRAN (R 3.5.1)
rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.1)
rstudioapi * 0.7 2017-09-07 CRAN (R 3.5.1)
sessioninfo 1.0.0 2017-06-21 CRAN (R 3.5.1)
stringi 1.2.4 2018-07-20 CRAN (R 3.5.1)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.1)
testthat * 2.0.0 2017-12-13 CRAN (R 3.5.1)
usethis * 1.4.0 2018-08-14 url
withr 2.1.2 2018-03-15 CRAN (R 3.5.1)
xml2 1.2.0 2018-01-24 CRAN (R 3.5.1)
yaml 2.2.0 2018-07-25 CRAN (R 3.5.1)
The first part of the code in build-book.r works for me:
install_github("hadley/oldbookdown#0ffc6fb") # code I needed to add
library(oldbookdown)
library(rmarkdown)
# Render chapters into tex ------------------------------------------------
needs_update <- function(src, dest) {
if (!file.exists(dest)) return(TRUE)
mtime <- file.info(src, dest)$mtime
mtime[2] < mtime[1]
}
render_chapter <- function(src) {
dest <- file.path("book/tex/", gsub("\\.rmd", "\\.tex", src))
if (!needs_update(src, dest)) return()
message("Rendering ", src)
command <- bquote(rmarkdown::render(.(src), oldbookdown::tex_chapter(),
output_dir = "book/tex", quiet = TRUE, env = globalenv()))
writeLines(deparse(command), "run.r")
on.exit(unlink("run.r"))
source_clean("run.r")
}
source_clean <- function(path) {
r_path <- file.path(R.home("bin"), "R")
cmd <- paste0(shQuote(r_path), " --quiet --file=", shQuote(path))
out <- system(cmd, intern = TRUE)
status <- attr(out, "status")
if (is.null(status)) status <- 0
if (!identical(as.character(status), "0")) {
stop("Command failed (", status, ")", call. = FALSE)
}
}
chapters <- dir(".", pattern = "\\.rmd$")
But the code fails when I try to actually render the chapters:
lapply(chapters, render_chapter)
Rendering check.rmd
Error: Command failed (1)
In addition: Warning message:
In system(cmd, intern = TRUE) :
running command '"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R" --quiet --file="run.r"' had status 1
Called from: source_clean("run.r")
Browse[1]
The system call fails, but since I don't know what the Windows call "C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R" --quiet --file="run.r" is supposed to do, I have no idea how to trouble shoot this. I tried changing r_path <- file.path(R.home("bin"), "R") to r_path <- file.path(R.home("bin")) (since there is no "R" directory in C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64), but I still get the error below:
lapply(chapters, render_chapter)
Rendering check.rmd
Error in system(cmd, intern = TRUE) :
'"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64"' not found
I also tried changing file.path(R.home("bin"), "R") to file.path(R.home("bin"), "R"), since there is a "R.exe" executable file in this directory, also with no luck. Any guidance would be appreciated.
Additional information, in response to #onlyphantom: it appears that the broken path is found by R.home("bin") has also affected other system variables, including R_DOC_DIR and R_HOME. But PATH points to the correct location, C:\Program Files\Microsoft\R Open\R-3.5.1\bin\x64.
file.path(R.home("bin"))
[1] "C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64"
Sys.getenv() # returned values below are redacted
APPDATA C:\Users\JT\AppData\Roaming
HOME C:/Users/JT/R/Projects
HOMEDRIVE C:
HOMEPATH \Users\JT\R
LOCALAPPDATA C:\Users\JT\AppData\Local
PATH C:\Program Files\Microsoft\R Open\R-3.5.1\bin\x64;...
ProgramData C:\ProgramData
ProgramFiles C:\Program Files
ProgramFiles(x86) C:\Program Files (x86)
R_DOC_DIR C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/doc
R_HOME C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1
R_LIBS_USER C:/Program Files/Microsoft/R Open/R-3.5.1/library
R_USER C:/Users/JT/R
I tried uninstalling and then reinstalling R Open, but still get this:
file.path(R.home("bin"), "R")
[1] "C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R"
I tried switching to regular R (instead of R Open) and continued to have the same problem.
Windows Command Line Problem: I walked step-by-step through the R code to find the exact location of the problem. It occurs when render_chapter() calls source_clean("run.r"), which eventually calls out <- system(cmd, intern = TRUE). cmd (for the first object in chapters) is "C:\Program Files\R\R-3.5.3\bin\x64\R" --quiet --file="run.r". When I open a Windows command prompt and run this code I get the following:
C:\>cd C:\Users\JT\R\Books\r-pkgs-first-edition-freeze
C:\Users...freeze>"C:\Program Files\R\R-3.5.3\bin\x64\R" --quiet --file="run.r"
> rmarkdown::render("check.rmd", oldbookdown::tex_chapter(), output_dir = "book/tex",
+ quiet = TRUE, env = globalenv())
--chapters has been removed. Use --top-level-division=chapter instead.
Try pandoc.exe --help for more information.
Error: pandoc document conversion failed with error 2
Execution halted
When I run pandoc.exe --help I see an entry --top-level-division=section|chapter|part. The switch away from --chapters happened after pandocs v1.17.2, so I uninstalled the current version and installed pandocs v1.17.2. I think this fixed the problem, but created a new problem. I now get this error (with either the short or long form of the path name):
C:\Users...freeze>"C:/PROGRA~1/R/R-35~1.3/bin/x64/R" --quiet --file="run.r"
#or#
C:\Users...freeze>"C:\Program Files\R\R-3.5.3\bin\x64\R" --quiet --file="run.r"
> rmarkdown::render("check.rmd", oldbookdown::tex_chapter(), output_dir = "book/
tex",
+ quiet = TRUE, env = globalenv())
pandoc.exe: Unknown reader: markdown_style
Error: pandoc document conversion failed with error 7
Execution halted
My assumption is that the old version of pandocs is not compatible with the new markdown_style. So I'm going to try installing the newest version of pandocs and then edit the run.r file to change --chapters to --top-level-division=section|chapter|part. If that's a stupid idea, please let me know.

The problem lies with a wrong R home directory. C:/PROGRA~1 is just the short form of path elements, and really points to C:/PROGRAM FILES/....
The same for R-35~1.1, it points to /R/R-3.5.1 or something. It's just a "short name".
The system call fails, but since I don't know what the Windows call
"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R" --quiet
--file="run.r" is supposed to do, I have no idea how to trouble shoot this.
Your script includes the following code:
source_clean <- function(path) {
r_path <- file.path(R.home("bin"), "R")
...
}
The value of r_path at this point is C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R, which may have resulted from a previous (or failed) installation of R Open.
I tried changing r_path <- file.path(R.home("bin"), "R") to r_path <-
file.path(R.home("bin")) (since there is no "R" directory in
C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64), but I still get the
error below:
"C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64"' not found
What you can do instead, is to set r_path directly to the directory containing your R installation. Open up R (in Rstudio or R console) and verify this:
file.path(R.home("bin"))
[1] "/Library/Frameworks/R.framework/Resources/bin"
Sys.getenv("R_HOME")
"/Library/Frameworks/R.framework/Resources"
The R.home function returns the R home directory. If you navigate to that exact location on your machine, you should see that's where your R installation is that.
Setting R environment variable on Windows
Let's say you find your R installation here C:\Program Files\R\R-3.3.2\bin\x86, then do the following:
Open Start Menu, type in "View advanced system settings" and hit "Environment variables".
Under "System variables", select Path and click on edit
Click “New”, and add the folder address for R to there (C:\Program Files\R\R-3.3.2\bin\x86)
Refer also to this answer and this for tips to set the path of your R home.

Turns out, there were two problems, both of which gave essentially the same error when lapply(chapters, render_chapter) was called. And it had nothing to do with the short version of the path (i.e. C:/PROGRA~1/MIE74D~1/ROPEN~1/R-35~1.1/bin/x64/R).
First, oldbookdown::tex_chapter() returned a list that was not compatible with the latest version of pandocs. So I changed the render_chapter function as follows:
render_chapter <- function(src) {
dest <- file.path("book/tex/", gsub("\\.rmd", "\\.tex", src))
if (!needs_update(src, dest)) return()
message("Rendering ", src)
# "changed oldbookdown::tex_chapter()" to "temp"
command <- bquote(rmarkdown::render(.(src), temp, output_dir = "book/tex", quiet = TRUE, env = globalenv()))
# added definition for temp (with appropriate changes to
# oldbookdown::tex_chapter()) to the writeLines() call
writeLines(
c(
"temp <- oldbookdown::tex_chapter()",
'temp$pandoc$from <- "markdown"',
'temp$pandoc$args[1] <- "--top-level-division=chapter"',
deparse(command)
),
"run.r"
)
on.exit(unlink("run.r"))
source_clean("run.r")
}
Second, pandocs was calling multiple R packages in the background and failing if they were not installed. So I had to call render_chapter on each object in chapters individually to identify and install the missing packages.
Now system("xelatex -interaction=batchmode r-packages ") is failing, but that's a topic for a different question.

Related

R session aborded package raster

Hello stackoverflow community,
I upgraded to the latest version of R and R studio this week, and have my R sessions encountering fatal error whenever I try to load the package raster.
I tried looking at the dependencies of the package, and re-installed all of them just to be sure.
# Install dependencies
db <- available.packages()
(deps <- tools::package_dependencies("raster", db)$raster)
# [1] "sp" "Rcpp" "methods"
install.packages(deps)
Any ideas?
Below are my session infos.
devtools::session_info("raster")
─ Session info ───────────────────────────────────────────────────────────────────
setting value
version R version 3.6.3 (2020-02-29)
os macOS Mojave 10.14.6
system x86_64, darwin15.6.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/New_York
date 2020-04-17
─ Packages ───────────────────────────────────────────────────────────────────────
package * version date lib source
lattice * 0.20-41 2020-04-02 [1] CRAN (R 3.6.2)
raster 3.0-12 2020-01-30 [1] CRAN (R 3.6.0)
Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 3.6.3)
sp 1.4-1 2020-02-28 [1] CRAN (R 3.6.0)
[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library
While looking for a solution, I also found out that my Makevars file is incomplete. I used the solution described in here, which asks RStudio to ensure it always saves files with a trailing newline, but it doesn't work here.
Problem is I don't know if I have had this issue for a long time, or whether it is related to the raster issue.
I tried loading >50 other packages, and the error seems to be tied to the raster library.
> writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
##CC=clang
##CXX=clang++
CPPFLAGS="-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
CC = gcc
CXX=/usr/local/bin/g++-9
CXX1X=/usr/local/clang6/bin/clang++
CXX98=/usr/local/clang6/bin/clang++
CXX11=/usr/local/clang6/bin/clang++
CXX14=/usr/local/clang6/bin/clang++
CXX17=/usr/local/clang6/bin/clang++
LDFLAGS=-L/usr/local/clang6/lib
Warning message:
In readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")) :
incomplete final line found on '/Users/Rosalie/.R/Makevars'
Thanks a lot in advance for any help you may be able to provide. I really have no idea what to test next!
Best,
Rosalie
The issue was with clang.
I first updated to macOS Catalina 10.15.4, then uninstalled the R development toolchain I had for previous version using this code. Then, I used some here:
In the terminal, I used the code xcode-select --install, that open a pop-up window. Press "Install", and follow the steps to install xcode.
Verify installation by taping in gcc --version.
Then, download and install the appropriate gfortran binary find correct version here.
In R, I re-installed Rcpp and raster install.packages("Rcpp", "raster").
I am now able to load the raster without the session abording!

Rmarkdown not working on Win 10 machine: openBinaryFile: does not exist (No such file or directory)

I am not able to knit html, pdf, or word. Same error each time:
"C:/Users/bosr/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output test.docx --highlight-style tango
pandoc.exe: test.utf8.md: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
Execution halted
I know there are many questions of this nature, but none that I have found have fixed my issue.
I installed R 3.6.1 and RStudio 1.2.1578 on a new Win 10 machine w/o admin rights. Managed to get everything working except Rmarkdown. My sessionInfo() is below. If I open a command prompt, pandoc is findable:
C:\>pandoc --version
pandoc 2.7.3
Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.8.1
Default user data directory: C:\Users\bosr\AppData\Roaming\pandoc
Copyright (C) 2006-2019 John MacFarlane
Web: http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
I have pandoc installed at C:\Users\bosr\AppData\Local\Pandoc\
I also tried #kevinushey's solution mentioned here
which resulted in a second pandoc install at H:\rstudio-pandoc\
Both pandoc installs are in my path (user) environment variable which I am allowed to set.
I would be very grateful for any suggestions.
- Session info -------------------------------------------------------
setting value
version R version 3.6.1 (2019-07-05)
os Windows 10 x64
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.1252
ctype English_United States.1252
tz America/New_York
date 2019-09-24
- Packages -----------------------------------------------------------
package * version date lib source
base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.1)
digest 0.6.21 2019-09-20 [1] CRAN (R 3.6.1)
evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1)
highr 0.8 2019-03-20 [1] CRAN (R 3.6.1)
htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.6.1)
jsonlite 1.6 2018-12-07 [1] CRAN (R 3.6.1)
knitr 1.25.1 2019-09-24 [1] Github (yihui/knitr#11ddfc6)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1)
markdown 1.1 2019-08-07 [1] CRAN (R 3.6.1)
mime 0.7 2019-06-11 [1] CRAN (R 3.6.0)
Rcpp 1.0.2 2019-07-25 [1] CRAN (R 3.6.1)
rmarkdown 1.15 2019-08-21 [1] CRAN (R 3.6.1)
stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1)
tinytex 0.16 2019-09-17 [1] CRAN (R 3.6.1)
xfun 0.9 2019-08-21 [1] CRAN (R 3.6.1)
yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0)
[1] C:/Users/bosr/R/R-3.6.1/library
[2] C:/pit
Update: I had IT install pandoc using the admin password, and I am still getting the same error:
"C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS riskNotes.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output riskReport_20190925.tex --table-of-contents --toc-depth 2 --template "C:\Users\bosr\R\R-3.6.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --no-highlight --pdf-engine pdflatex --variable graphics=yes --variable "compact-title:yes"
pandoc.exe: riskNotes.utf8.md: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
In addition: There were 22 warnings (use warnings() to see them)
Ok, I see now this is due to the file being saved on a network drive. See here. There is no fix yet. Too bad.
I have had a similar error and resolved it by uninstalling all stand-alone versions of Pandoc. In my case I had a separate Pandoc version 2.9.2.1 installed, verified by running the following in R Studio:
rmarkdown::pandoc_version()
# 2.9.2.1
rmarkdown::pandoc_exec()
# "C:/Program File~/pandoc/pandoc"
Uninstalling this version allowed me to render even network files and yielded the folowing after a reboot:
rmarkdown::pandoc_version()
# 1.19.2.1
rmarkdown::pandoc_exec()
# "C:/Program Files/RStudio/bin/pandoc/pandoc"
I had the same problem. The reason was that there was an old .RHistory file in the same folder as the RMarkdown document, which was taken over into a new project due to copying an old folder. By deleting this .RHistory file, I was able to fix the problem.

Strange (distortred) output in RStudio notebook in R 3.5.1

I noticed strange behavior in RStudio notebook in R 3.5.1. I can reproduce the behavior by using this code:
list()
head(iris)
At first, an empty list should be printed. Then, if any data frame is printed in either the same or another code chunk, its values get enclosed with additional symbols (some are indicated with arrows) as in this print screen.
In R 3.5.1:
This behavior might be related to this issue with R lists. It is present in notebooks and disappears if the code is run a console or if the document is knitted. In R 3.4.4 this issue is also not present.
If additional code is run between the list and data frame, the issue disappears as well, e.g.:
list()
1
head(iris)
I have these questions:
I use Windows. Can Linux and Mac OS users reproduce the issue?
How can the causes of the distortion in the output be explained?
Where should I report the issue if I want it to be solved in the future?
Session info ---------------------------------------------------------------------------------------
setting value
version R version 3.5.1 (2018-07-02)
system x86_64, mingw32
ui RStudio (1.1.453)
language (EN)
collate English_United States.1252
tz Europe/Helsinki
date 2018-07-15
Packages -------------------------------------------------------------------------------------------
package * version date source
base * 3.5.1 2018-07-02 local
compiler 3.5.1 2018-07-02 local
datasets * 3.5.1 2018-07-02 local
devtools 1.13.6 2018-06-27 CRAN (R 3.5.0)
digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
graphics * 3.5.1 2018-07-02 local
grDevices * 3.5.1 2018-07-02 local
knitr 1.20.8 2018-07-07 Github (yihui/knitr#89b34a6)
memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
methods * 3.5.1 2018-07-02 local
stats * 3.5.1 2018-07-02 local
tools 3.5.1 2018-07-02 local
utils * 3.5.1 2018-07-02 local
withr 2.1.2 2018-06-28 Github (jimhester/withr#fe56f20)
xfun 0.3 2018-07-06 CRAN (R 3.5.0)
yaml 2.1.19 2018-05-01 CRAN (R 3.5.0)
It appears that this is a bug that affects GUI applications using R 3.5.1 on Windows (e.g. RGui and RStudio). For example, you can see a similar effect with:
x <- 1
print(list())
save(x, file = tempfile())
output <- encodeString("apple")
print(output)
Sourcing this gives, for me:
> source('~/encoding.R')
list()
[1] "\002ÿþapple\003ÿþ"
We'll have a fix in the next version of RStudio, but for now the workaround is to just avoid printing empty lists before printing data frames in R.

R bookdown, fontawesome5, render fails but file knits just fine in RStudio

Experiencing an odd issue... using MacTeX 2018, current versions of all packages, R and RStudio ditto... I can knit a file containing fontawesome5 icons just fine in RStudio, however, render() is failing and I need to use render in a makefile to automate a build process... render() appears to set in motion a call to latexmk that appears to call tlmgr on fonts that already exist which then halts with a file not found error... any suggestions would be most welcome, hair successfully pulled out over this... thanks in advance!
Below is a minimal file needed to replicate (debug.Rmd in what follows):
---
output:
bookdown::pdf_document2:
toc: no
latex_engine: lualatex
header-includes:
- \usepackage{fontawesome5}
---
- \faIcon{phone}
If you remove \faIcon{phone} it renders fine and of course also builds fine in RStudio.
Here is the error message (session info follows)
Rscript -e 'rmarkdown::render("debug.Rmd",bookdown::pdf_document2(toc = FALSE))'
processing file: debug.Rmd
|.................................................................| 100%
ordinary text without R code
output file: debug.knit.md
/usr/local/bin/pandoc +RTS -K512m -RTS debug.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output debug.tex --template /Users/jracine/Library/R/rmarkdown/rmd/latex/default-1.17.0.2.tex --number-sections --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes' --variable tables=yes --standalone
tlmgr search --file --global '/fa5free0solid[.](tfm|afm|mf|otf)'
Trying to automatically install missing LaTeX packages...
tlmgr install fontawesome5
tlmgr: package repository http://ctan.mirror.colo-serv.net/systems/texlive/tlnet (verified)
tlmgr install: package already present: fontawesome5
tlmgr path add
tlmgr search --file --global '/fa5free0solid[.](tfm|afm|mf|otf)'
Output created: debug.pdf
Error in tools::file_path_as_absolute(output_file) :
file 'debug.pdf' does not exist
Calls: <Anonymous> -> <Anonymous>
Execution halted
Session Info:
Session info ------------------------------------------------------------------
setting value
version R version 3.5.0 (2018-04-23)
system x86_64, darwin17.5.0
ui X11
language (EN)
collate en_CA.UTF-8
tz America/Toronto
date 2018-06-24
Packages ----------------------------------------------------------------------
package * version date source
backports 1.1.2 2017-12-13 CRAN (R 3.5.0)
base64enc 0.1-3 2015-07-28 CRAN (R 3.5.0)
bookdown 0.7.13 2018-06-18 Github (rstudio/bookdown#dda5f5a)
digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
evaluate 0.10.1 2017-06-24 CRAN (R 3.5.0)
glue 1.2.0 2017-10-29 CRAN (R 3.5.0)
graphics * 3.5.0 2018-04-23 local
grDevices * 3.5.0 2018-04-23 local
highr 0.7 2018-06-09 CRAN (R 3.5.0)
htmltools 0.3.6 2017-04-28 CRAN (R 3.5.0)
jsonlite 1.5 2017-06-01 CRAN (R 3.5.0)
knitr 1.20.6 2018-06-22 Github (yihui/knitr#2b3e617)
magrittr 1.5 2014-11-22 CRAN (R 3.5.0)
markdown 0.8 2017-04-20 CRAN (R 3.5.0)
methods * 3.5.0 2018-04-23 local
mime 0.5 2016-07-07 CRAN (R 3.5.0)
Rcpp 0.12.17 2018-05-18 CRAN (R 3.5.0)
rmarkdown 1.10.2 2018-06-22 Github (rstudio/rmarkdown#1f5b299)
rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.0)
stats * 3.5.0 2018-04-23 local
stringi 1.2.3 2018-06-12 CRAN (R 3.5.0)
stringr 1.3.1 2018-05-10 CRAN (R 3.5.0)
tinytex 0.5 2018-04-16 CRAN (R 3.5.0)
tools 3.5.0 2018-04-23 local
utils * 3.5.0 2018-04-23 local
xfun 0.2.5 2018-06-22 Github (yihui/xfun#b75336c)
yaml 2.1.19 2018-05-01 CRAN (R 3.5.0)
> rmarkdown::pandoc_version()
[1] ‘2.2.1’
> system('pdflatex --version')
pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018)
kpathsea version 6.3.0
Copyright 2018 Han The Thanh (pdfTeX) et al.
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.34; using libpng 1.6.34
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.00
Your Makefile is wrong. When you call
Rscript -e 'rmarkdown::render("debug.Rmd",bookdown::pdf_document2(toc = FALSE))'
you essentially overrode the settings in your YAML metadata (such as latex_engine) with bookdown::pdf_document2(toc = FALSE), which has the default latex_engine = 'pdflatex'. That is why your intermediate .tex output was compiled with pdflatex instead of lualatex.
Either call
Rscript -e 'rmarkdown::render("debug.Rmd")'
if bookdown::pdf_document2 is the only output format you need, or call
Rscript -e 'rmarkdown::render("debug.Rmd", "bookdown::pdf_document2")'
if you have multiple output formats set in YAML.
For the second argument of rmarkdown::render() (e.g., the output format), you should rarely need the form of an output format function that returns an output format (e.g., bookdown::pdf_document2(...)). In most cases, I believe the default (NULL, meaning the first format you set in YAML), or a character string (the name of the format you set in YAML) should be what you want.

R Markdown - opt_hooks not exported

Hi I am completely new to R markdown but everytime I try to knit and creat an html file it gives me this error
Error: 'opts_hooks' is not an exported object from 'namespace:knitr'
Execution halted
Can someone please help me? I have installed the knitr package but I don't know how to export opt_hooks.
I got the same issue, i guess this is an update of rmarkdown/rstudio button (didn't check) because this workaround works fine :
# to md
knit("myRmarkdown.Rmd")
# to html
knit2html("myRmarkdown.md")
Hope it helps.
PS: session info dump :
> devtools::session_info()
Session info ------------------------------------------------------------------------------------------------------------------------------
setting value
version R version 3.2.0 (2015-04-16)
system x86_64, linux-gnu
ui RStudio (0.99.902)
language (EN)
collate fr_FR.UTF-8
tz Europe/Paris
Packages ----------------------------------------------------------------------------------------------------------------------------------
package * version date source
devtools 1.8.0 2015-05-09 CRAN (R 3.2.0)
knitr * 1.11 2015-08-14 CRAN (R 3.2.0)
rmarkdown 0.9.6 2016-05-01 CRAN (R 3.2.0)

Resources