0

Using RSTudio > Blogdown > Hugo to create a blog Inserting this R in a post. When the HTML is rendered there are commas between the rotated letters. Why is that?

enter image description here

library("knitr")
library("kableExtra")
library("dplyr")
library("formattable")
library("stringr")
library("tidyverse")

p1 <- c("R Markdown is pretty neat. You can do things like this. I wonder why more people don't")
p1 <- c("Hello World!")
p2 <- c("do this. It's so much easier to read. NOTE: Those people live here.")

p_text <- unlist(strsplit(p1, "")) # strsplit returns a list. Make it a vector.
num_char <- length(p_text)

p_angle <- seq(30, 360, 30) 
num_ang <- length(p_angle)
p_angle_long <- rep(p_angle, ceiling(num_char / num_ang))  # Repeat the angles for the length of the string
p_angle_long <- p_angle_long[1:num_char]

rtext <- text_spec(p_text, "html", bold = TRUE, angle = p_angle_long)
ixodid
  • 2,180
  • 1
  • 19
  • 46

1 Answers1

2

The output of text_spec is a vector with each letter (+ accompanying HTML tags) as a separate element. You can combine into a single string with paste0:

# Example RMarkdown chunk that produces rotated text:
```{r txt, results='asis'}
library("knitr")
library("kableExtra")
library("tidyverse")

p1 <- c("Hello World!")
p2 <- c("do this. It's so much easier to read. NOTE: Those people live here.")

p_text <- unlist(strsplit(p1, "")) # strsplit returns a list. Make it a vector.
num_char <- length(p_text)

p_angle <- seq(30, 360, 30) 
num_ang <- length(p_angle)
p_angle_long <- rep(p_angle, ceiling(num_char / num_ang))  
# Repeat the angles for the length of the string
p_angle_long <- p_angle_long[1:num_char]

rtext <- text_spec(p_text, "html", bold = TRUE, angle = p_angle_long)
cat(paste0(rtext, collapse=""))
```
Marius
  • 58,213
  • 16
  • 107
  • 105