Strange (distortred) output in RStudio notebook in R 3.5.1 - r

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.

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!

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

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.

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.

Separate User Library and System Library in RStudio's Packages pane under Windows 10?

I'm setting up R/RStudio on a new Windows 10 machine; first time setting it up in a non-UNIX environment, so bear with me.
From my previous experience with R/RStudio under Linux and macOS, I wanted to setup separate libraries for system and user, i.e., that the Packages pane in RStudio would show both a User Library AND a System Library.
I specified the R_LIBS_USER environment variable for my account as C:\Users\[user name]\Documents\R\win-library\3.5.
When running R/RStudio, the .libPaths() are as follows:
> .libPaths()
[1] "C:/Users/[user name]/Documents/R/win-library/3.5"
[2] "C:/Program Files/R/R-3.5.0/library"
This is pretty much what I wanted: the first library path being the default User Library, and the second path being the System Library. I'm able to install packages at will, and they are per default located inside the User Library.
HOWEVER, the Packages pane in RStudio does NOT show two separate libraries for the User Library and the System Library. Instead, all packages (aside from base) are shown under System Library; including the packages from my User Library. My question now is:
Is there a way to tell R/RStudio that my User Library and my System Library are two separate entities, which should be visually separated in RStudio's Packages pane?
Note: I'm aware this is likely a mere "cosmetic" issue; but it still bothers me! Also, I'm not sure if this is a pure R or an RStudio issue, so I tagged both.
EDIT: I also noticed that the System Library (C:/Program Files/R/R-3.5.0/library) is not available as drop-down option when installing new packages inside the Packages pane.
--
> devtools::session_info()
Session info --------------------------------------------------------------
setting value
version R version 3.5.0 (2018-04-23)
system x86_64, mingw32
ui RStudio (1.1.453)
language (EN)
collate Nothing to worry about
tz This neither
date 2018-06-08
Packages ------------------------------------------------------------------
package * version date source
base * 3.5.0 2018-04-23 local
compiler 3.5.0 2018-04-23 local
datasets * 3.5.0 2018-04-23 local
devtools 1.13.5 2018-02-18 CRAN (R 3.5.0)
digest 0.6.15 2018-01-28 CRAN (R 3.5.0)
graphics * 3.5.0 2018-04-23 local
grDevices * 3.5.0 2018-04-23 local
memoise 1.1.0 2017-04-21 CRAN (R 3.5.0)
methods * 3.5.0 2018-04-23 local
stats * 3.5.0 2018-04-23 local
tools 3.5.0 2018-04-23 local
utils * 3.5.0 2018-04-23 local
withr 2.1.2 2018-03-15 CRAN (R 3.5.0)
yaml 2.1.19 2018-05-01 CRAN (R 3.5.0)
I had exactly the same issue. In my case the cause was using a substituted drive for the user libraries:
> subst
F:\: => C:\data\flash drive
Setting R_LIBS_USER to F:/[...] shows the cosmetic error, using C:/data/flash drive/[...] works.
In my case, Sys.getenv("R_LIBS_USER") is as follow:
"C:\\Users\\USERNAME\\AppData\\Local/R/win-library/4.2"
This path includes two backslashes, so this was causing the environment variable to not be recognized correctly.
Next I searched for a place to put .Renviron as follows
R.home(component = "etc")
I created .Renviron (or Renviro.site) in that folder and saved it with the following in the contents and it worked.
R_LIBS_USER=C:/Users/${USERNAME}/AppData/Local/R/win-library/%v

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