R中的字符向量与knitr一起作为分项列表 [英] Character vector in R as itemized list with knitr

查看:66
本文介绍了R中的字符向量与knitr一起作为分项列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向量(例如letters),我想将其作为项列表并入我的.Rnw编织文件中.我该怎么做?

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?

我已经尝试过\Sexpr{letters},但是它只是在每个逗号之间放置了逗号:

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?

我正在寻找类似的结果

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

推荐答案

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

或者,更优雅的是,使用虚拟条目代替显式的\item:

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 ")
@

这篇关于R中的字符向量与knitr一起作为分项列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆