Hello! I wonder if anyone here is able to point me to how to get further with my troubleshooting of an Rmd document that used to knit before but recently has failed to do so. I have isolated the problem to a specific chunk that calls a plotly function that includes some interactive features.
When I run the chunks I do not get any warnings of problems with the function. It's only when I try to knit that it fails to produce the html document with the correct styling of the left sidebar and it throws an error:
Error in if (title == x2) return(head) : the condition has length > 1
Calls: <Anonymous> ... split_chapters -> build -> sub -> is.factor -> prepend_chapter_title
Execution halted
It seems to me a problem that is slightly more advanced than what I normally deal with. I provide a minimum reprex here together with the session info. I would appreciate any suggestions. Thank you!
---
title: "Supplementary Information"
author: "Tan, M., Xie, X., Jaeger, T. F."
date: "`r Sys.Date()`"
header-includes:
- \usepackage{booktabs}
- \usepackage{siunitx}
- \usepackage{tabto}
- \usepackage{soul}
- \usepackage{xcolor}
- \usepackage{placeins}
- \usepackage{lscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
- \makeatletter\renewcommand{\fps@table}{!ht}\makeatother
- \setstcolor{red}
- \usepackage{sectsty}
- \sectionfont{\color{red}}
- \subsectionfont{\color{red}}
- \subsubsectionfont{\color{red}}
output:
bookdown::gitbook:
split_by: rmd
self_contained: true
config:
toc:
collapse: subsection
scroll_highlight: yes
before: null
after: null
toolbar:
position: static
edit : null
download: null
search: yes
documentclass: book
always_allow_html: true
citation_package: BibTex
bibliography: [refs.bib]
link-citations: yes
csl: frontiers-in-psychology.csl
---
<style type="text/css">
div.main-container {
max-width: 1800px;
margin-left: auto;
margin-right: auto;
}
</style>
knitr::opts_chunk$set(echo = FALSE,
message=FALSE, warning=TRUE, error=TRUE, cache = FALSE)
library(bookdown)
library(tidyverse)
library(magrittr)
library(knitr)
library(plotly) # 3D plotting
library(shiny) # tabs
# set plot themes
theme_set(
theme_bw() +
theme(panel.border = element_blank(),
axis.title.x = element_text(margin = margin(t = 20)),
axis.title.y = element_text(margin = margin(r = 20)))
)
colors.Accent = colors.Group
colors.Category = c("blue", "orange")
colors.Language = c("cyan", "pink")
shapes.Category = c("circle","square")
Example
# make dataframe
d.stims.long <-
tibble(
NativeLanguage = rep("English", 20),
Accent = rep("native", 20),
Used_for = rep("training", 20),
Item.Word = rep(c("pet", "bet", "pound", "bound", "but", "bud", "white", "wide", "gilt", "gild"), 2),
Sound = rep(c("/t/", "/d/"), 10),
ContextCorrected = rep(c("uncorrected", "step 1"), each = 10),
vowel = c(rnorm(10, 220, 90), rnorm(10, 20, 90)),
closure = c(rnorm(10, 185, 97), rnorm(10, 18, 75)),
burst = c(rnorm(10, 165, 92), rnorm(10, 12, 80)))
# function to make 3d plot with interactive slider
plot_corrected_cues <- function(.data, title = "Correction step") {
plot_ly(data = .data %>%
droplevels(),
frame= ~ContextCorrected,
ids= ~Item.Word,
x= ~vowel,
y= ~closure,
z= ~burst,
text= ~Item.Word,
color= ~Sound,
colors = colors.Category,
opacity = .35,
symbol= ~Used_for,
symbols = shapes.Category,
hoverinfo = "text", showlegend = T,
type="scatter3d", mode="markers") %>%
animation_slider(
currentvalue = list(prefix = paste0(title, ": "),
font = list(color="black"))
)
}
# call function to make 3D plot
plot_corrected_cues(
d.stims.long %>%
filter(NativeLanguage == "English",
Accent == "native"))
Session info
options(width = 120)
devtools::session_info()