4

I have a vector (e.g. letters) that I want to incorporate into my .Rnw knitr document as an itemized list. How do I do this?

I have tried \Sexpr{letters} but it merely places commas between each:

a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z

Something like this is just as unhelpful:

\begin{itemize}
\item[\Sexpr{letters}]
\end{itemize}

What is the proper way to do this?

I'm looking for a result like:

  • a
  • b
  • c
  • d
  • e
  • f

etc.

CephBirk
  • 6,422
  • 5
  • 56
  • 74

3 Answers3

4

Or

\documentclass{article}
\begin{document}

Here is a list.

\begin{itemize}
<<results="asis", echo=FALSE>>=
cat(sprintf('\\item{%s}', letters[1:5]), sep = '\n')
@
\end{itemize}

That was a list.

\end{document}

enter image description here

rawr
  • 20,481
  • 4
  • 44
  • 78
3
\documentclass{article}
\begin{document}
\begin{itemize}
  \item
<<results="asis", echo=FALSE>>=
  lets = letters[1:5]
  cat(lets, sep="\n\\item ")
@
\end{itemize}
\end{document}

Or, more elegantly, with a dummy entry instead of the explicit \item:

<<results="asis", echo=FALSE>>=
  lets = letters[1:5]
  cat("", lets, sep="\n\\item ")
@
Dieter Menne
  • 10,076
  • 44
  • 67
0

You can use the character vector in code block as follows to knit to PDF format (logn strings automatically wrap to next lines, '\n' ensures correct formatting of bullet points:

---
title: "Bullet from string"
author: "author"
date: '2022-06-22'
output: pdf_document
---

Blabla... here your bullet list comes:

```{r mwe, include=TRUE, results = 'asis'}
str_example <- c(
 'a', 'b', 'c', 'd', 'e'
  )
str_example <- paste0('* ', str_example, '\n')
cat(str_example)
```

enter image description here

ToWii
  • 590
  • 5
  • 8