Converting LaTeX tables into R dataframes/matrices

坚强是说给别人听的谎言 提交于 2021-02-19 06:27:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!