问题
The process of converting R outputs into LaTeX is well documented. However, the opposite not so much. The problem: I have a long LaTeX file and would like to import the tables it into R (say, convert them as data frames).
Question: is there an elegant/efficient way of doing this task without having to do it manually?
Note that there are percent signs (%) commenting the rows in the tables.
For example,
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\title{Processing \LaTeX{} tables with R}
\begin{document}
\maketitle
\section{Introduction}
Here is the first table
\begin{table}[h]
\centering
\caption{Some data}
\begin{tabular}{l|l|}
c1 & c2\\\hline
a & b \\% comments
c & \cite{mypaper} \\% # more comments
\end{tabular}
\end{table}
and the second:
\begin{table}[h]
\centering
\caption{More data}
\begin{tabular}{ll}
1 & 2 \\% mycomment:"first row"
3 & 4 \\
\end{tabular}
\end{table}
\end{document}
Desired output in R:
## Table 1
c1 c2
a b
c cite{mypaper}
## Table 2
1 2
3 4
来源:https://stackoverflow.com/questions/49375555/converting-latex-tables-into-r-dataframes-matrices