I have a question about inline R Markdown code:

I have a finished LaTeX table that looks like this:

\begin{tabular}{ |c|c|c|c|} 
$\textbf{Vorname}$ &  $\textbf{Nachname}$ & $\textbf{Email}$ & $\textbf{Stimmen}$  \\ 
`r Table[[2]][[1,1]]` & `r Table[[2]][[1,2]]` & `r Table[[2]][[1,3]]` & `r Table[[2]][[1,4]]`\\ \hline
`r Table[[2]][[2,1]]` & `r Table[[2]][[2,2]]` & `r Table[[2]][[2,3]]` & `r Table[[2]][[2,4]]`\\ \hline

Here, I inserted some inline code (e.g. Table[[2]][[1,1]]) for the entries of the cell. Using the notation r [R code]. Now I would like to make this table dynamic: The amount of rows if supposed to be be given by a variable n.

So I want something of this kind:

[LaTex code]
j =0
for (j in 1:n){ 
`r Table[[2]][[j,1]]` & `r Table[[2]][[j,2]]` & `r Table[[j]][[1,3]]` & `r Table[[2]][[j,4]]` \\ \hline }

How can I achieve that?

  • Without see R code generating a fake Tableobject and a whole rmarkdown file to test it, is hard to guess what you are trying, but anyway my advice is not make a LaTeX table with R chunks code in every cell, but construct first the table as a R dataframe (if Table is not already this) and then export the whole dataframe to LaTeX using xtable or kable. This last part could be as simple as library(xtable); xtable(yourdataframe). – Fran Apr 14 at 13:05
  • ok thank you very much – stefanR Apr 14 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.